Skip to content

Commit 57a0cc2

Browse files
committed
Add finally.
1 parent 50107c3 commit 57a0cc2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Control/Monad/Aff.purs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ module Control.Monad.Aff
106106
apathize :: forall e a. Aff e a -> Aff e Unit
107107
apathize a = const unit <$> attempt a
108108

109+
-- | Compute `aff1`, followed by `aff2` regardless of whether `aff1` terminated successfully.
110+
finally :: forall e a. Aff e a -> Aff e Unit -> Aff e a
111+
finally aff1 aff2 = do
112+
x <- attempt aff1
113+
aff2
114+
either throwError pure x
115+
109116
-- | Lifts a synchronous computation and makes explicit any failure from exceptions.
110117
liftEff' :: forall e a. Eff (err :: Exception | e) a -> Aff e (Either Error a)
111118
liftEff' eff = attempt (_unsafeInterleaveAff (runFn2 _liftEff nonCanceler eff))

0 commit comments

Comments
 (0)