1
- module Control.Monad.Aff
1
+ module Control.Monad.Aff
2
2
( Aff ()
3
3
, Canceler (..)
4
4
, PureAff (..)
@@ -12,10 +12,11 @@ module Control.Monad.Aff
12
12
, launchAff
13
13
, liftEff'
14
14
, makeAff
15
+ , makeAff'
15
16
, nonCanceler
16
17
, runAff
17
18
)
18
- where
19
+ where
19
20
20
21
import Data.Either (Either (..), either )
21
22
import Data.Function (Fn2 (), Fn3 (), runFn2 , runFn3 )
@@ -31,7 +32,7 @@ module Control.Monad.Aff
31
32
import Control.Monad.Eff.Class
32
33
import Control.Monad.Error.Class (MonadError , throwError )
33
34
34
- -- | A computation with effects `e`. The computation either errors or
35
+ -- | A computation with effects `e`. The computation either errors or
35
36
-- | produces a value of type `a`.
36
37
-- |
37
38
-- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
@@ -54,24 +55,24 @@ module Control.Monad.Aff
54
55
cancelWith :: forall e a. Aff e a -> Canceler e -> Aff e a
55
56
cancelWith aff c = runFn3 _cancelWith nonCanceler aff c
56
57
57
- -- | Converts the asynchronous computation into a synchronous one. All values
58
+ -- | Converts the asynchronous computation into a synchronous one. All values
58
59
-- | and errors are ignored.
59
60
launchAff :: forall e a. Aff e a -> Eff e Unit
60
61
launchAff = runAff (const (pure unit)) (const (pure unit))
61
62
62
- -- | Runs the asynchronous computation. You must supply an error callback and a
63
+ -- | Runs the asynchronous computation. You must supply an error callback and a
63
64
-- | success callback.
64
65
runAff :: forall e a. (Error -> Eff e Unit ) -> (a -> Eff e Unit ) -> Aff e a -> Eff e Unit
65
66
runAff ex f aff = runFn3 _runAff ex f aff
66
67
67
- -- | Creates an asynchronous effect from a function that accepts error and
68
+ -- | Creates an asynchronous effect from a function that accepts error and
68
69
-- | success callbacks. This function can be used for asynchronous computations
69
70
-- | that cannot be canceled.
70
71
makeAff :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e Unit ) -> Aff e a
71
72
makeAff h = makeAff' (\e a -> const nonCanceler <$> h e a )
72
73
73
- -- | Creates an asynchronous effect from a function that accepts error and
74
- -- | success callbacks, and returns a canceler for the computation. This
74
+ -- | Creates an asynchronous effect from a function that accepts error and
75
+ -- | success callbacks, and returns a canceler for the computation. This
75
76
-- | function can be used for asynchronous computations that can be canceled.
76
77
makeAff' :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e (Canceler e)) -> Aff e a
77
78
makeAff' h = _makeAff h
@@ -84,7 +85,7 @@ module Control.Monad.Aff
84
85
later' :: forall e a. Number -> Aff e a -> Aff e a
85
86
later' n aff = runFn3 _setTimeout nonCanceler n aff
86
87
87
- -- | Forks the specified asynchronous computation so subsequent monadic binds
88
+ -- | Forks the specified asynchronous computation so subsequent monadic binds
88
89
-- | will not block on the result of the computation.
89
90
forkAff :: forall e a. Aff e a -> Aff e (Canceler e )
90
91
forkAff aff = runFn2 _forkAff nonCanceler aff
@@ -128,7 +129,7 @@ module Control.Monad.Aff
128
129
instance monadEffAff :: MonadEff e (Aff e ) where
129
130
liftEff eff = runFn2 _liftEff nonCanceler eff
130
131
131
- -- | Allows users to catch and throw errors on the error channel of the
132
+ -- | Allows users to catch and throw errors on the error channel of the
132
133
-- | asynchronous computation. See documentation in `purescript-transformers`.
133
134
instance monadErrorAff :: MonadError Error (Aff e ) where
134
135
throwError e = runFn2 _throwError nonCanceler e
@@ -278,7 +279,7 @@ module Control.Monad.Aff
278
279
} catch (e) {
279
280
error(e);
280
281
}
281
-
282
+
282
283
return canceler;
283
284
}
284
285
}" " " :: forall e a. Fn2 (Canceler e ) a (Aff e a )
@@ -287,7 +288,7 @@ module Control.Monad.Aff
287
288
function _throwError(canceler, e) {
288
289
return function(success, error) {
289
290
error(e);
290
-
291
+
291
292
return canceler;
292
293
}
293
294
}" " " :: forall e a. Fn2 (Canceler e ) Error (Aff e a )
@@ -309,15 +310,15 @@ module Control.Monad.Aff
309
310
function _bind(aff, f) {
310
311
return function(success, error) {
311
312
var canceler;
312
-
313
+
313
314
canceler = aff(function(v) {
314
- try {
315
+ try {
315
316
canceler = f(v)(success, error);
316
317
} catch (e) {
317
318
error(e);
318
319
}
319
320
}, error);
320
-
321
+
321
322
return function(e) {
322
323
return function(success, error) {
323
324
return canceler(e)(success, error);
@@ -368,7 +369,7 @@ module Control.Monad.Aff
368
369
} catch (e) {
369
370
error(e);
370
371
}
371
-
372
+
372
373
return canceler;
373
374
};
374
375
}" " " :: forall e a. Fn2 (Canceler e ) (Eff e a ) (Aff e a )
0 commit comments