@@ -37,20 +37,20 @@ asynchronously without any callbacks. Error handling is baked in so you only
37
37
deal with it when you want to.
38
38
39
39
The library contains instances for ` Semigroup ` , ` Monoid ` , ` Apply ` ,
40
- ` Applicative ` , ` Bind ` , ` Monad ` , ` Alt ` , ` Plus ` , ` MonadEff ` , ` MonadError ` , and
40
+ ` Applicative ` , ` Bind ` , ` Monad ` , ` Alt ` , ` Plus ` , ` MonadEffect ` , ` MonadError ` , and
41
41
` Parallel ` . These instances allow you to compose asynchronous code as easily
42
- as ` Eff ` , as well as interop with existing ` Eff ` code.
42
+ as ` Effect ` , as well as interop with existing ` Effect ` code.
43
43
44
44
## Escaping Callback Hell
45
45
46
46
Hopefully, you're using libraries that already use the ` Aff ` type, so you
47
47
don't even have to think about callbacks!
48
48
49
49
If you're building your own library, then you can make an ` Aff ` from
50
- low-level ` Eff ` callbacks with ` makeAff ` .
50
+ low-level ` Effect ` callbacks with ` makeAff ` .
51
51
52
52
``` purescript
53
- makeAff :: forall eff a. ((Either Error a -> Eff eff Unit) -> Eff eff ( Canceler eff)) -> Aff eff a
53
+ makeAff :: forall a. ((Either Error a -> Effect Unit) -> Effect Canceler) -> Aff a
54
54
```
55
55
56
56
This function expects you to provide a handler, which should call the
@@ -60,7 +60,7 @@ You should also return `Canceler`, which is just a cleanup effect. Since
60
60
` Aff ` threads may be killed, all asynchronous operations should provide a
61
61
mechanism for unscheduling it.
62
62
63
- ` Control.Monad .Aff.Compat` provides functions for easily binding FFI
63
+ ` Effect .Aff.Compat` provides functions for easily binding FFI
64
64
definitions:
65
65
66
66
``` javascript
@@ -84,14 +84,14 @@ exports._ajaxGet = function (request) { // accepts a request
84
84
```
85
85
86
86
``` purescript
87
- foreign import _ajaxGet :: forall eff. Request -> EffFnAff (ajax :: AJAX | eff) Response
87
+ foreign import _ajaxGet :: Request -> EffectFnAff Response
88
88
```
89
89
90
90
We can wrap this into an asynchronous computation like so:
91
91
92
92
``` purescript
93
- ajaxGet :: forall eff. Request -> Aff (ajax :: AJAX | eff) Response
94
- ajaxGet = fromEffFnAff <<< _ajaxGet
93
+ ajaxGet :: Request -> Aff Response
94
+ ajaxGet = fromEffectFnAff <<< _ajaxGet
95
95
```
96
96
97
97
This eliminates callback hell and allows us to write code simply using ` do `
@@ -103,22 +103,18 @@ example = do
103
103
log response.body
104
104
```
105
105
106
- ## Eff
106
+ ## Effect
107
107
108
- All purely synchronous computations (` Eff ` ) can be lifted to asynchronous
109
- computations with ` liftEff ` defined in ` Control.Monad.Eff .Class` .
108
+ All purely synchronous computations (` Effect ` ) can be lifted to asynchronous
109
+ computations with ` liftEffect ` defined in ` Effect .Class` .
110
110
111
111
``` purescript
112
- liftEff $ log "Hello world!"
112
+ liftEffect $ log "Hello world!"
113
113
```
114
114
115
115
This lets you write your whole program in ` Aff ` , and still call out to
116
116
synchronous code.
117
117
118
- If your ` Eff ` code throws exceptions (` exception :: EXCEPTION ` ), you can
119
- remove the exception label using ` liftEff' ` . Exceptions are part of ` Aff ` s
120
- built-in semantics, so they will always be caught and propagated anyway.
121
-
122
118
## Dealing with Failure
123
119
124
120
` Aff ` has error handling baked in, so ordinarily you don't have to worry
@@ -188,7 +184,7 @@ Because Javascript is single-threaded, forking does not actually cause the
188
184
computation to be run in a separate thread. Forking just allows the subsequent
189
185
actions to execute without waiting for the forked computation to complete.
190
186
191
- Forking returns a ` Fiber eff a ` , representing the deferred computation. You can
187
+ Forking returns a ` Fiber a ` , representing the deferred computation. You can
192
188
kill a ` Fiber ` with ` killFiber ` , which will run any cancelers and cleanup, and
193
189
you can observe a ` Fiber ` 's final value with ` joinFiber ` . If a ` Fiber ` threw
194
190
an exception, it will be rethrown upon joining.
@@ -203,53 +199,6 @@ example = do
203
199
else (log "Not Canceled")
204
200
```
205
201
206
-
207
- ## AVars
208
-
209
- The ` Control.Monad.Aff.AVar ` module contains asynchronous variables, which
210
- are very similar to Haskell's ` MVar ` .
211
-
212
- ` AVar ` s represent a value that is either full or empty. Calling ` takeVar ` on
213
- an empty ` AVar ` will queue until it is filled by a ` putVar ` .
214
-
215
- ``` purescript
216
- example = do
217
- var <- makeEmptyVar
218
- _ <- forkAff do
219
- value <- takeVar var
220
- log $ "Got a value: " <> value
221
- _ <- forkAff do
222
- delay (Milliseconds 100.0)
223
- putVar var "hello"
224
- pure unit
225
- ```
226
- ```
227
- (Waits 100ms)
228
- > Got a value: hello
229
- ```
230
-
231
- Likewise, calling ` putVar ` on a filled ` AVar ` will queue until it is emptied by
232
- a ` takeVar ` .
233
-
234
- ``` purescript
235
- example = do
236
- var <- makeVar "hello"
237
- _ <- forkAff do
238
- delay (Milliseconds 100.0)
239
- value <- takeVar var
240
- log $ "Got a value: " <> value
241
- putVar var "next"
242
- log "Value put"
243
- ```
244
- ```
245
- (Waits 100ms)
246
- > Got a value: hello
247
- > Value put
248
- ```
249
-
250
- These combinators (and a few more) can be used as the building blocks for
251
- complex asynchronous coordination.
252
-
253
202
## Parallel Execution
254
203
255
204
The ` Parallel ` instance for ` Aff ` makes writing parallel computations a breeze.
0 commit comments