@@ -5,9 +5,11 @@ module Control.Monad.Aff
5
5
, Canceler (..)
6
6
, makeAff
7
7
, launchAff
8
+ , launchAff_
8
9
, launchSuspendedAff
9
10
, runAff
10
11
, runAff_
12
+ , runSuspendedAff
11
13
, forkAff
12
14
, suspendAff
13
15
, liftEff'
@@ -146,10 +148,10 @@ type OnComplete eff a =
146
148
-- | Represents a forked computation by way of `forkAff`. `Fiber`s are
147
149
-- | memoized, so their results are only computed once.
148
150
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 ))
150
153
, join ∷ (Either Error a → Eff eff Unit ) → Eff eff (Eff eff Unit )
151
154
, onComplete ∷ OnComplete eff a → Eff eff (Eff eff Unit )
152
- , run ∷ Eff eff Unit
153
155
}
154
156
155
157
instance functorFiber ∷ Functor (Fiber eff ) where
@@ -197,6 +199,10 @@ launchAff aff = do
197
199
case fiber of Fiber f → f.run
198
200
pure fiber
199
201
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
+
200
206
-- | Suspends an `Aff` from an `Eff` context, returning the `Fiber`.
201
207
launchSuspendedAff ∷ ∀ eff a . Aff eff a → Eff eff (Fiber eff a )
202
208
launchSuspendedAff = makeFiber
@@ -211,11 +217,16 @@ runAff k aff = launchAff $ liftEff <<< k =<< try aff
211
217
runAff_ ∷ ∀ eff a . (Either Error a → Eff eff Unit ) → Aff eff a → Eff eff Unit
212
218
runAff_ k aff = void $ runAff k aff
213
219
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
+
214
225
-- | Forks am `Aff` from within a parent `Aff` context, returning the `Fiber`.
215
226
forkAff ∷ ∀ eff a . Aff eff a → Aff eff (Fiber eff a )
216
227
forkAff = _fork true
217
228
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`.
219
230
-- | A suspended `Aff` is not executed until a consumer observes the result
220
231
-- | with `joinFiber`.
221
232
suspendAff ∷ ∀ eff a . Aff eff a → Aff eff (Fiber eff a )
0 commit comments