Skip to content

Commit 46951cf

Browse files
committed
Fixes #11, Fixes #10
1 parent 20d4062 commit 46951cf

File tree

6 files changed

+153
-298
lines changed

6 files changed

+153
-298
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,19 @@ canceled <- canceler $ error "Just had to cancel"
171171
_ <- liftEff $ if canceled then (trace "Canceled") else (trace "Not Canceled")
172172
```
173173

174-
## Queues
174+
## AVars
175175

176-
The `Control.Monad.Aff.Queue` module contains asynchronous queues. These can
177-
be used as low-level building blocks for asynchronous programs.
176+
The `Control.Monad.Aff.AVar` module contains asynchronous variables, which are very similar to Haskell's `MVar` construct. These can be used as low-level building blocks for asynchronous programs.
178177

179178
```purescript
180-
do v <- makeQueue
181-
forkAff (later $ putQueue v 1.0)
182-
a <- takeQueue v
179+
do v <- makeVar
180+
forkAff (later $ putVar v 1.0)
181+
a <- takeVar v
183182
liftEff $ trace ("Succeeded with " ++ show a)
184183
```
185184

186185
You can use these constructs as one-sided blocking queues, which suspend (if
187-
necessary) on `take` operations, or as asynchronous variables (similar to
188-
Haskell's `MVar` construct).
186+
necessary) on `take` operations, or as asynchronous, empty-or-full variables.
189187

190188
## Parallel Execution
191189

examples/src/Examples.purs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Examples where
44
import Data.Either(either)
55

66
import Control.Monad.Aff
7-
import Control.Monad.Aff.Queue
7+
import Control.Monad.Aff.AVar
88
import Control.Monad.Aff.Par
99
import Control.Apply((*>))
1010
import Control.Alt(Alt, (<|>))
@@ -13,7 +13,7 @@ module Examples where
1313
import Control.Monad.Error.Class(throwError)
1414

1515
type Test = forall e. Aff (trace :: Trace | e) Unit
16-
type TestQueue = forall e. Aff (trace :: Trace, queue :: QueueFx | e) Unit
16+
type TestAVar = forall e. Aff (trace :: Trace, avar :: AVAR | e) Unit
1717

1818
test_sequencing :: Number -> Test
1919
test_sequencing 0 = liftEff $ trace "Done"
@@ -38,33 +38,33 @@ module Examples where
3838
apathize $ throwError (error "Oh noes!")
3939
liftEff $ trace "Success: Exceptions don't stop the apathetic"
4040

41-
test_putTakeQueue :: TestQueue
41+
test_putTakeQueue :: TestAVar
4242
test_putTakeQueue = do
43-
v <- makeQueue
44-
forkAff (later $ putQueue v 1.0)
45-
a <- takeQueue v
43+
v <- makeVar
44+
forkAff (later $ putVar v 1.0)
45+
a <- takeVar v
4646
liftEff $ trace ("Success: Value " ++ show a)
4747

48-
test_killQueue :: TestQueue
48+
test_killQueue :: TestAVar
4949
test_killQueue = do
50-
v <- makeQueue
51-
killQueue v (error "DOA")
52-
e <- attempt $ takeQueue v
50+
v <- makeVar
51+
killVar v (error "DOA")
52+
e <- attempt $ takeVar v
5353
liftEff $ either (const $ trace "Success: Killed queue dead") (const $ trace "Failure: Oh noes, queue survived!") e
5454

55-
test_parRace :: TestQueue
55+
test_parRace :: TestAVar
5656
test_parRace = do
5757
s <- runPar (Par (later' 100 $ pure "Success: Early bird got the worm") <|>
5858
Par (later' 200 $ pure "Failure: Late bird got the worm"))
5959
liftEff $ trace s
6060

61-
test_parRaceKill1 :: TestQueue
61+
test_parRaceKill1 :: TestAVar
6262
test_parRaceKill1 = do
6363
s <- runPar (Par (later' 100 $ throwError (error ("Oh noes!"))) <|>
6464
Par (later' 200 $ pure "Success: Early error was ignored in favor of late success"))
6565
liftEff $ trace s
6666

67-
test_parRaceKill2 :: TestQueue
67+
test_parRaceKill2 :: TestAVar
6868
test_parRaceKill2 = do
6969
e <- attempt $ runPar (Par (later' 100 $ throwError (error ("Oh noes!"))) <|>
7070
Par (later' 200 $ throwError (error ("Oh noes!"))))
@@ -86,10 +86,10 @@ module Examples where
8686
liftEff $ trace "Testing apathize"
8787
test_apathize
8888

89-
liftEff $ trace "Testing Queue - putQueue, takeQueue"
89+
liftEff $ trace "Testing Queue - putVar, takeVar"
9090
test_putTakeQueue
9191

92-
liftEff $ trace "Testing killQueue"
92+
liftEff $ trace "Testing killVar"
9393
test_killQueue
9494

9595
liftEff $ trace "Testing Par (<|>)"

0 commit comments

Comments
 (0)