@@ -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.
148150newtype 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
155157instance functorFiber ∷ Functor (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`.
201207launchSuspendedAff ∷ ∀ eff a . Aff eff a → Eff eff (Fiber eff a )
202208launchSuspendedAff = makeFiber
@@ -211,11 +217,16 @@ runAff k aff = launchAff $ liftEff <<< k =<< try aff
211217runAff_ ∷ ∀ eff a . (Either Error a → Eff eff Unit ) → Aff eff a → Eff eff Unit
212218runAff_ 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`.
215226forkAff ∷ ∀ eff a . Aff eff a → Aff eff (Fiber eff a )
216227forkAff = _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`.
221232suspendAff ∷ ∀ eff a . Aff eff a → Aff eff (Fiber eff a )
0 commit comments