Skip to content

Commit afd67da

Browse files
committed
add later
1 parent f093554 commit afd67da

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

MODULES.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ produces a value of type `a`.
2929

3030
This is moral equivalent of `ErrorT (ContT Unit (EffA e)) a`.
3131

32-
The type implements `MonadEff` so it's easy to lift synchronous `Eff`
33-
computations into this type. As a result, there's basically no reason to
34-
use `Eff` in a program that has some asynchronous computations.
35-
3632
#### `PureAff`
3733

3834
``` purescript
@@ -46,16 +42,16 @@ type PureAff a = forall e. Aff e a
4642
launchAff :: forall e a. Aff e a -> EffA e Unit
4743
```
4844

49-
Converts the asynchronous effect into a synchronous one. All values and
50-
errors are ignored.
45+
Converts the asynchronous computation into a synchronous one. All values
46+
and errors are ignored.
5147

5248
#### `runAff`
5349

5450
``` purescript
5551
runAff :: forall e a. (Error -> Eff e Unit) -> (a -> Eff e Unit) -> Aff e a -> EffA e Unit
5652
```
5753

58-
Runs the asynchronous effect. You must supply an error callback and a
54+
Runs the asynchronous computation. You must supply an error callback and a
5955
success callback.
6056

6157
#### `makeAff`
@@ -67,6 +63,14 @@ makeAff :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> EffA e Uni
6763
Creates an asynchronous effect from a function that accepts error and
6864
success callbacks.
6965

66+
#### `later`
67+
68+
``` purescript
69+
later :: forall e a. Aff e a -> Aff e a
70+
```
71+
72+
Runs the asynchronous computation later.
73+
7074
#### `forkAff`
7175

7276
``` purescript

src/Control/Monad/Aff.purs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module Control.Monad.Aff
55
, PureAff(..)
66
, attempt
77
, forkAff
8+
, later
89
, launchAff
910
, liftEff'
1011
, makeAff
@@ -35,20 +36,16 @@ module Control.Monad.Aff
3536
-- | produces a value of type `a`.
3637
-- |
3738
-- | This is moral equivalent of `ErrorT (ContT Unit (EffA e)) a`.
38-
-- |
39-
-- | The type implements `MonadEff` so it's easy to lift synchronous `Eff`
40-
-- | computations into this type. As a result, there's basically no reason to
41-
-- | use `Eff` in a program that has some asynchronous computations.
4239
data Aff e a = Aff ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> EffA e Unit)
4340

4441
type PureAff a = forall e. Aff e a
4542

46-
-- | Converts the asynchronous effect into a synchronous one. All values and
47-
-- | errors are ignored.
43+
-- | Converts the asynchronous computation into a synchronous one. All values
44+
-- | and errors are ignored.
4845
launchAff :: forall e a. Aff e a -> EffA e Unit
4946
launchAff (Aff fa) = fa (const (pure unit)) (const (pure unit))
5047

51-
-- | Runs the asynchronous effect. You must supply an error callback and a
48+
-- | Runs the asynchronous computation. You must supply an error callback and a
5249
-- | success callback.
5350
runAff :: forall e a. (Error -> Eff e Unit) -> (a -> Eff e Unit) -> Aff e a -> EffA e Unit
5451
runAff ex f (Aff v) = v ex f
@@ -58,6 +55,19 @@ module Control.Monad.Aff
5855
makeAff :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> EffA e Unit) -> Aff e a
5956
makeAff = Aff
6057

58+
-- | Runs the asynchronous computation later.
59+
foreign import later """
60+
function later(aff) {
61+
return function(error) {
62+
return function(success) {
63+
return function() {
64+
setTimeout(aff(error)(success), 0);
65+
}
66+
}
67+
}
68+
}
69+
""" :: forall e a. Aff e a -> Aff e a
70+
6171
-- | Forks the specified asynchronous computation so subsequent monadic binds
6272
-- | will not block on the result of the computation.
6373
foreign import forkAff """

0 commit comments

Comments
 (0)