1
- module Control.Monad.Aff
1
+ module Control.Monad.Aff
2
2
( Aff ()
3
3
, Canceler ()
4
4
, PureAff (..)
@@ -10,10 +10,11 @@ module Control.Monad.Aff
10
10
, launchAff
11
11
, liftEff'
12
12
, makeAff
13
+ , makeAff'
13
14
, nonCanceler
14
15
, runAff
15
16
)
16
- where
17
+ where
17
18
18
19
import Data.Either (Either (..), either )
19
20
import Data.Function (Fn2 (), Fn3 (), runFn2 , runFn3 )
@@ -29,7 +30,7 @@ module Control.Monad.Aff
29
30
import Control.Monad.Eff.Class
30
31
import Control.Monad.Error.Class (MonadError , throwError )
31
32
32
- -- | A computation with effects `e`. The computation either errors or
33
+ -- | A computation with effects `e`. The computation either errors or
33
34
-- | produces a value of type `a`.
34
35
-- |
35
36
-- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
@@ -40,24 +41,24 @@ module Control.Monad.Aff
40
41
41
42
type Canceler e = Error -> Aff e Boolean
42
43
43
- -- | Converts the asynchronous computation into a synchronous one. All values
44
+ -- | Converts the asynchronous computation into a synchronous one. All values
44
45
-- | and errors are ignored.
45
46
launchAff :: forall e a. Aff e a -> Eff e Unit
46
47
launchAff = runAff (const (pure unit)) (const (pure unit))
47
48
48
- -- | Runs the asynchronous computation. You must supply an error callback and a
49
+ -- | Runs the asynchronous computation. You must supply an error callback and a
49
50
-- | success callback.
50
51
runAff :: forall e a. (Error -> Eff e Unit ) -> (a -> Eff e Unit ) -> Aff e a -> Eff e Unit
51
52
runAff ex f aff = runFn3 _runAff ex f aff
52
53
53
- -- | Creates an asynchronous effect from a function that accepts error and
54
+ -- | Creates an asynchronous effect from a function that accepts error and
54
55
-- | success callbacks. This function can be used for asynchronous computations
55
56
-- | that cannot be canceled.
56
57
makeAff :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e Unit ) -> Aff e a
57
58
makeAff h = makeAff' (\e a -> const nonCanceler <$> h e a )
58
59
59
- -- | Creates an asynchronous effect from a function that accepts error and
60
- -- | success callbacks, and returns a canceler for the computation. This
60
+ -- | Creates an asynchronous effect from a function that accepts error and
61
+ -- | success callbacks, and returns a canceler for the computation. This
61
62
-- | function can be used for asynchronous computations that can be canceled.
62
63
makeAff' :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e (Canceler e)) -> Aff e a
63
64
makeAff' h = _makeAff h
@@ -70,7 +71,7 @@ module Control.Monad.Aff
70
71
later' :: forall e a. Number -> Aff e a -> Aff e a
71
72
later' n aff = runFn3 _setTimeout nonCanceler n aff
72
73
73
- -- | Forks the specified asynchronous computation so subsequent monadic binds
74
+ -- | Forks the specified asynchronous computation so subsequent monadic binds
74
75
-- | will not block on the result of the computation.
75
76
forkAff :: forall e a. Aff e a -> Aff e (Canceler e )
76
77
forkAff aff = runFn2 _forkAff nonCanceler aff
@@ -114,7 +115,7 @@ module Control.Monad.Aff
114
115
instance monadEffAff :: MonadEff e (Aff e ) where
115
116
liftEff eff = runFn2 _liftEff nonCanceler eff
116
117
117
- -- | Allows users to catch and throw errors on the error channel of the
118
+ -- | Allows users to catch and throw errors on the error channel of the
118
119
-- | asynchronous computation. See documentation in `purescript-transformers`.
119
120
instance monadErrorAff :: MonadError Error (Aff e ) where
120
121
throwError e = runFn2 _throwError nonCanceler e
@@ -149,7 +150,7 @@ module Control.Monad.Aff
149
150
return canceler(e)(success, error);
150
151
} else {
151
152
cancel = true;
152
-
153
+
153
154
clearTimeout(timeout);
154
155
155
156
try {
@@ -216,7 +217,7 @@ module Control.Monad.Aff
216
217
} catch (e) {
217
218
error(e);
218
219
}
219
-
220
+
220
221
return canceler;
221
222
}
222
223
}" " " :: forall e a. Fn2 (Canceler e ) a (Aff e a )
@@ -225,7 +226,7 @@ module Control.Monad.Aff
225
226
function _throwError(canceler, e) {
226
227
return function(success, error) {
227
228
error(e);
228
-
229
+
229
230
return canceler;
230
231
}
231
232
}" " " :: forall e a. Fn2 (Canceler e ) Error (Aff e a )
@@ -247,15 +248,15 @@ module Control.Monad.Aff
247
248
function _bind(aff, f) {
248
249
return function(success, error) {
249
250
var canceler;
250
-
251
+
251
252
canceler = aff(function(v) {
252
- try {
253
+ try {
253
254
canceler = f(v)(success, error);
254
255
} catch (e) {
255
256
error(e);
256
257
}
257
258
}, error);
258
-
259
+
259
260
return function(e) {
260
261
return function(success, error) {
261
262
return canceler(e)(success, error);
@@ -306,7 +307,7 @@ module Control.Monad.Aff
306
307
} catch (e) {
307
308
error(e);
308
309
}
309
-
310
+
310
311
return canceler;
311
312
};
312
313
}" " " :: forall e a. Fn2 (Canceler e ) (Eff e a ) (Aff e a )
0 commit comments