Skip to content

Commit 200f2fe

Browse files
committed
Add launchAff_ and runSuspendedAff
1 parent ae7a9f7 commit 200f2fe

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Control/Monad/Aff.purs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ module Control.Monad.Aff
55
, Canceler(..)
66
, makeAff
77
, launchAff
8+
, launchAff_
89
, launchSuspendedAff
910
, runAff
1011
, runAff_
12+
, runSuspendedAff
1113
, forkAff
1214
, suspendAff
1315
, liftEff'
@@ -146,10 +148,10 @@ type OnComplete eff a =
146148
-- | Represents a forked computation by way of `forkAff`. `Fiber`s are
147149
-- | memoized, so their results are only computed once.
148150
newtype Fiber eff a = Fiber
149-
{ kill Fn.Fn2 Error (Either Error Unit Eff eff Unit) (Eff eff (Eff eff Unit))
151+
{ run Eff eff Unit
152+
, kill Fn.Fn2 Error (Either Error Unit Eff eff Unit) (Eff eff (Eff eff Unit))
150153
, join (Either Error a Eff eff Unit) Eff eff (Eff eff Unit)
151154
, onComplete OnComplete eff a Eff eff (Eff eff Unit)
152-
, run Eff eff Unit
153155
}
154156

155157
instance functorFiberFunctor (Fiber eff) where
@@ -197,6 +199,10 @@ launchAff aff = do
197199
case fiber of Fiber f → f.run
198200
pure fiber
199201

202+
-- | Forks an `Aff` from an `Eff` context, discarding the `Fiber`.
203+
launchAff_ eff a. Aff eff a Eff eff Unit
204+
launchAff_ = void <<< launchAff
205+
200206
-- | Suspends an `Aff` from an `Eff` context, returning the `Fiber`.
201207
launchSuspendedAff eff a. Aff eff a Eff eff (Fiber eff a)
202208
launchSuspendedAff = makeFiber
@@ -211,11 +217,16 @@ runAff k aff = launchAff $ liftEff <<< k =<< try aff
211217
runAff_ eff a. (Either Error a Eff eff Unit) Aff eff a Eff eff Unit
212218
runAff_ k aff = void $ runAff k aff
213219

220+
-- | Suspends an `Aff` from an `Eff` context and also takes a callback to run
221+
-- | when it completes. Returns the suspended `Fiber`.
222+
runSuspendedAff eff a. (Either Error a Eff eff Unit) Aff eff a Eff eff (Fiber eff Unit)
223+
runSuspendedAff k aff = launchSuspendedAff $ liftEff <<< k =<< try aff
224+
214225
-- | Forks am `Aff` from within a parent `Aff` context, returning the `Fiber`.
215226
forkAff eff a. Aff eff a Aff eff (Fiber eff a)
216227
forkAff = _fork true
217228

218-
-- | Suspends n `Aff` from within a parent `Aff` context, returning the `Fiber`.
229+
-- | Suspends an `Aff` from within a parent `Aff` context, returning the `Fiber`.
219230
-- | A suspended `Aff` is not executed until a consumer observes the result
220231
-- | with `joinFiber`.
221232
suspendAff eff a. Aff eff a Aff eff (Fiber eff a)

0 commit comments

Comments
 (0)