@@ -33,20 +33,20 @@ module Control.Monad.Aff
33
33
import Control.Monad.Eff.Class
34
34
import Control.Monad.Error.Class (MonadError , throwError )
35
35
36
- -- | An asynchronous computation with effects `e`. The computation either
36
+ -- | An asynchronous computation with effects `e`. The computation either
37
37
-- | errors or produces a value of type `a`.
38
38
-- |
39
39
-- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
40
40
foreign import data Aff :: # ! -> * -> *
41
41
42
- -- | A pure asynchronous computation, having no effects other than
42
+ -- | A pure asynchronous computation, having no effects other than
43
43
-- | asynchronous computation.
44
44
type PureAff a = forall e. Aff e a
45
45
46
- -- | A canceler is asynchronous function that can be used to attempt the
46
+ -- | A canceler is asynchronous function that can be used to attempt the
47
47
-- | cancelation of a computation. Returns a boolean flag indicating whether
48
48
-- | or not the cancellation was successful. Many computations may be composite,
49
- -- | in such cases the flag indicates whether any part of the computation was
49
+ -- | in such cases the flag indicates whether any part of the computation was
50
50
-- | successfully canceled. The flag should not be used for communication.
51
51
newtype Canceler e = Canceler (Error -> Aff e Boolean )
52
52
@@ -55,7 +55,7 @@ module Control.Monad.Aff
55
55
cancel (Canceler f ) = f
56
56
57
57
-- | This function allows you to attach a custom canceler to an asynchronous
58
- -- | computation. If the computation is canceled, then the custom canceler
58
+ -- | computation. If the computation is canceled, then the custom canceler
59
59
-- | will be run along side the computation's own canceler.
60
60
cancelWith :: forall e a. Aff e a -> Canceler e -> Aff e a
61
61
cancelWith aff c = runFn3 _cancelWith nonCanceler aff c
@@ -86,7 +86,7 @@ module Control.Monad.Aff
86
86
later :: forall e a. Aff e a -> Aff e a
87
87
later = later' 0
88
88
89
- -- | Runs the specified asynchronous computation later, by the specified
89
+ -- | Runs the specified asynchronous computation later, by the specified
90
90
-- | number of milliseconds.
91
91
later' :: forall e a. Number -> Aff e a -> Aff e a
92
92
later' n aff = runFn3 _setTimeout nonCanceler n aff
@@ -101,7 +101,7 @@ module Control.Monad.Aff
101
101
-- | Forks the specified asynchronous computation so subsequent computations
102
102
-- | will not block on the result of the computation.
103
103
-- |
104
- -- | Returns a canceler that can be used to attempt cancellation of the
104
+ -- | Returns a canceler that can be used to attempt cancellation of the
105
105
-- | forked computation.
106
106
forkAff :: forall e a. Aff e a -> Aff e (Canceler e )
107
107
forkAff aff = runFn2 _forkAff nonCanceler aff
@@ -205,7 +205,7 @@ module Control.Monad.Aff
205
205
};
206
206
207
207
canceler2(e)(s, f);
208
- canceler1(e)(s, f);
208
+ canceler1(e)(s, f);
209
209
210
210
return nonCanceler;
211
211
};
@@ -216,10 +216,15 @@ module Control.Monad.Aff
216
216
217
217
foreign import _setTimeout " " "
218
218
function _setTimeout(nonCanceler, millis, aff) {
219
+ var set = setTimeout, clear = clearTimeout;
220
+ if (millis <= 0 && typeof setImmediate === " function" ) {
221
+ set = setImmediate;
222
+ clear = clearImmediate;
223
+ }
219
224
return function(success, error) {
220
225
var canceler;
221
226
222
- var timeout = setTimeout (function() {
227
+ var timeout = set (function() {
223
228
canceler = aff(success, error);
224
229
}, millis);
225
230
@@ -228,7 +233,7 @@ module Control.Monad.Aff
228
233
if (canceler !== undefined) {
229
234
return canceler(e)(s, f);
230
235
} else {
231
- clearTimeout (timeout);
236
+ clear (timeout);
232
237
233
238
try {
234
239
s(true);
0 commit comments