Skip to content

Commit a8efcf2

Browse files
committed
Merge pull request #15 from garyb/export-cancelable
Export makeAff'
2 parents 9d0987d + aef5f1b commit a8efcf2

File tree

2 files changed

+41
-23
lines changed

2 files changed

+41
-23
lines changed

MODULES.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
data Aff :: # ! -> * -> *
99
```
1010

11-
A computation with effects `e`. The computation either errors or
11+
A computation with effects `e`. The computation either errors or
1212
produces a value of type `a`.
1313

1414
This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
@@ -34,7 +34,7 @@ type Canceler e = Error -> Aff e Boolean
3434
launchAff :: forall e a. Aff e a -> Eff e Unit
3535
```
3636

37-
Converts the asynchronous computation into a synchronous one. All values
37+
Converts the asynchronous computation into a synchronous one. All values
3838
and errors are ignored.
3939

4040
#### `runAff`
@@ -43,7 +43,7 @@ and errors are ignored.
4343
runAff :: forall e a. (Error -> Eff e Unit) -> (a -> Eff e Unit) -> Aff e a -> Eff e Unit
4444
```
4545

46-
Runs the asynchronous computation. You must supply an error callback and a
46+
Runs the asynchronous computation. You must supply an error callback and a
4747
success callback.
4848

4949
#### `makeAff`
@@ -52,10 +52,20 @@ success callback.
5252
makeAff :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e Unit) -> Aff e a
5353
```
5454

55-
Creates an asynchronous effect from a function that accepts error and
55+
Creates an asynchronous effect from a function that accepts error and
5656
success callbacks. This function can be used for asynchronous computations
5757
that cannot be canceled.
5858

59+
#### `makeAff'`
60+
61+
``` purescript
62+
makeAff' :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e (Canceler e)) -> Aff e a
63+
```
64+
65+
Creates an asynchronous effect from a function that accepts error and
66+
success callbacks, and returns a canceler for the computation. This
67+
function can be used for asynchronous computations that can be canceled.
68+
5969
#### `later`
6070

6171
``` purescript
@@ -78,7 +88,7 @@ Runs the asynchronous computation later (off the current execution context).
7888
forkAff :: forall e a. Aff e a -> Aff e (Canceler e)
7989
```
8090

81-
Forks the specified asynchronous computation so subsequent monadic binds
91+
Forks the specified asynchronous computation so subsequent monadic binds
8292
will not block on the result of the computation.
8393

8494
#### `attempt`
@@ -175,7 +185,7 @@ instance monadEffAff :: MonadEff e (Aff e)
175185
instance monadErrorAff :: MonadError Error (Aff e)
176186
```
177187

178-
Allows users to catch and throw errors on the error channel of the
188+
Allows users to catch and throw errors on the error channel of the
179189
asynchronous computation. See documentation in `purescript-transformers`.
180190

181191
#### `altAff`
@@ -209,6 +219,9 @@ instance monadPlusAff :: MonadPlus (Aff e)
209219

210220
## Module Control.Monad.Aff.AVar
211221

222+
223+
A low-level primitive for building asynchronous code.
224+
212225
#### `AVAR`
213226

214227
``` purescript
@@ -300,6 +313,10 @@ instance monadAffAff :: MonadAff e (Aff e)
300313

301314
## Module Control.Monad.Aff.Par
302315

316+
317+
A newtype over `Aff` that provides `Applicative` instances that run in
318+
parallel.
319+
303320
#### `Par`
304321

305322
``` purescript

src/Control/Monad/Aff.purs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module Control.Monad.Aff
1+
module Control.Monad.Aff
22
( Aff()
33
, Canceler()
44
, PureAff(..)
@@ -10,10 +10,11 @@ module Control.Monad.Aff
1010
, launchAff
1111
, liftEff'
1212
, makeAff
13+
, makeAff'
1314
, nonCanceler
1415
, runAff
1516
)
16-
where
17+
where
1718

1819
import Data.Either(Either(..), either)
1920
import Data.Function(Fn2(), Fn3(), runFn2, runFn3)
@@ -29,7 +30,7 @@ module Control.Monad.Aff
2930
import Control.Monad.Eff.Class
3031
import Control.Monad.Error.Class(MonadError, throwError)
3132

32-
-- | A computation with effects `e`. The computation either errors or
33+
-- | A computation with effects `e`. The computation either errors or
3334
-- | produces a value of type `a`.
3435
-- |
3536
-- | This is moral equivalent of `ErrorT (ContT Unit (Eff e)) a`.
@@ -40,24 +41,24 @@ module Control.Monad.Aff
4041

4142
type Canceler e = Error -> Aff e Boolean
4243

43-
-- | Converts the asynchronous computation into a synchronous one. All values
44+
-- | Converts the asynchronous computation into a synchronous one. All values
4445
-- | and errors are ignored.
4546
launchAff :: forall e a. Aff e a -> Eff e Unit
4647
launchAff = runAff (const (pure unit)) (const (pure unit))
4748

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
4950
-- | success callback.
5051
runAff :: forall e a. (Error -> Eff e Unit) -> (a -> Eff e Unit) -> Aff e a -> Eff e Unit
5152
runAff ex f aff = runFn3 _runAff ex f aff
5253

53-
-- | Creates an asynchronous effect from a function that accepts error and
54+
-- | Creates an asynchronous effect from a function that accepts error and
5455
-- | success callbacks. This function can be used for asynchronous computations
5556
-- | that cannot be canceled.
5657
makeAff :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e Unit) -> Aff e a
5758
makeAff h = makeAff' (\e a -> const nonCanceler <$> h e a)
5859

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
6162
-- | function can be used for asynchronous computations that can be canceled.
6263
makeAff' :: forall e a. ((Error -> Eff e Unit) -> (a -> Eff e Unit) -> Eff e (Canceler e)) -> Aff e a
6364
makeAff' h = _makeAff h
@@ -70,7 +71,7 @@ module Control.Monad.Aff
7071
later' :: forall e a. Number -> Aff e a -> Aff e a
7172
later' n aff = runFn3 _setTimeout nonCanceler n aff
7273

73-
-- | Forks the specified asynchronous computation so subsequent monadic binds
74+
-- | Forks the specified asynchronous computation so subsequent monadic binds
7475
-- | will not block on the result of the computation.
7576
forkAff :: forall e a. Aff e a -> Aff e (Canceler e)
7677
forkAff aff = runFn2 _forkAff nonCanceler aff
@@ -114,7 +115,7 @@ module Control.Monad.Aff
114115
instance monadEffAff :: MonadEff e (Aff e) where
115116
liftEff eff = runFn2 _liftEff nonCanceler eff
116117

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
118119
-- | asynchronous computation. See documentation in `purescript-transformers`.
119120
instance monadErrorAff :: MonadError Error (Aff e) where
120121
throwError e = runFn2 _throwError nonCanceler e
@@ -149,7 +150,7 @@ module Control.Monad.Aff
149150
return canceler(e)(success, error);
150151
} else {
151152
cancel = true;
152-
153+
153154
clearTimeout(timeout);
154155
155156
try {
@@ -216,7 +217,7 @@ module Control.Monad.Aff
216217
} catch (e) {
217218
error(e);
218219
}
219-
220+
220221
return canceler;
221222
}
222223
}""" :: forall e a. Fn2 (Canceler e) a (Aff e a)
@@ -225,7 +226,7 @@ module Control.Monad.Aff
225226
function _throwError(canceler, e) {
226227
return function(success, error) {
227228
error(e);
228-
229+
229230
return canceler;
230231
}
231232
}""" :: forall e a. Fn2 (Canceler e) Error (Aff e a)
@@ -247,15 +248,15 @@ module Control.Monad.Aff
247248
function _bind(aff, f) {
248249
return function(success, error) {
249250
var canceler;
250-
251+
251252
canceler = aff(function(v) {
252-
try {
253+
try {
253254
canceler = f(v)(success, error);
254255
} catch (e) {
255256
error(e);
256257
}
257258
}, error);
258-
259+
259260
return function(e) {
260261
return function(success, error) {
261262
return canceler(e)(success, error);
@@ -306,7 +307,7 @@ module Control.Monad.Aff
306307
} catch (e) {
307308
error(e);
308309
}
309-
310+
310311
return canceler;
311312
};
312313
}""" :: forall e a. Fn2 (Canceler e) (Eff e a) (Aff e a)

0 commit comments

Comments
 (0)