@@ -33,20 +33,20 @@ module Control.Monad.Aff
3333 import Control.Monad.Eff.Class
3434 import Control.Monad.Error.Class (MonadError , throwError )
3535
36- -- | An asynchronous computation with effects `e`. The computation either
36+ -- | An asynchronous computation with effects `e`. The computation either
3737 -- | errors or produces a value of type `a`.
3838 -- |
3939 -- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
4040 foreign import data Aff :: # ! -> * -> *
4141
42- -- | A pure asynchronous computation, having no effects other than
42+ -- | A pure asynchronous computation, having no effects other than
4343 -- | asynchronous computation.
4444 type PureAff a = forall e. Aff e a
4545
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
4747 -- | cancelation of a computation. Returns a boolean flag indicating whether
4848 -- | 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
5050 -- | successfully canceled. The flag should not be used for communication.
5151 newtype Canceler e = Canceler (Error -> Aff e Boolean )
5252
@@ -55,7 +55,7 @@ module Control.Monad.Aff
5555 cancel (Canceler f ) = f
5656
5757 -- | 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
5959 -- | will be run along side the computation's own canceler.
6060 cancelWith :: forall e a. Aff e a -> Canceler e -> Aff e a
6161 cancelWith aff c = runFn3 _cancelWith nonCanceler aff c
@@ -86,7 +86,7 @@ module Control.Monad.Aff
8686 later :: forall e a. Aff e a -> Aff e a
8787 later = later' 0
8888
89- -- | Runs the specified asynchronous computation later, by the specified
89+ -- | Runs the specified asynchronous computation later, by the specified
9090 -- | number of milliseconds.
9191 later' :: forall e a. Number -> Aff e a -> Aff e a
9292 later' n aff = runFn3 _setTimeout nonCanceler n aff
@@ -101,7 +101,7 @@ module Control.Monad.Aff
101101 -- | Forks the specified asynchronous computation so subsequent computations
102102 -- | will not block on the result of the computation.
103103 -- |
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
105105 -- | forked computation.
106106 forkAff :: forall e a. Aff e a -> Aff e (Canceler e )
107107 forkAff aff = runFn2 _forkAff nonCanceler aff
@@ -205,7 +205,7 @@ module Control.Monad.Aff
205205 };
206206
207207 canceler2(e)(s, f);
208- canceler1(e)(s, f);
208+ canceler1(e)(s, f);
209209
210210 return nonCanceler;
211211 };
@@ -216,10 +216,15 @@ module Control.Monad.Aff
216216
217217 foreign import _setTimeout " " "
218218 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+ }
219224 return function(success, error) {
220225 var canceler;
221226
222- var timeout = setTimeout (function() {
227+ var timeout = set (function() {
223228 canceler = aff(success, error);
224229 }, millis);
225230
@@ -228,7 +233,7 @@ module Control.Monad.Aff
228233 if (canceler !== undefined) {
229234 return canceler(e)(s, f);
230235 } else {
231- clearTimeout (timeout);
236+ clear (timeout);
232237
233238 try {
234239 s(true);
0 commit comments