Skip to content

Commit 78aed83

Browse files
committed
Par added but not yet working
1 parent fe46347 commit 78aed83

File tree

6 files changed

+339
-94
lines changed

6 files changed

+339
-94
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ block the current thread of execution:
150150
forkAff myAff
151151
```
152152

153-
Because Javascript is single-threaded, forking does not actually cause the computation to be run in a separate thread. Forking just allows the subsequent actions to execute without waiting for the forked computation to complete.
153+
Because Javascript is single-threaded, forking does not actually cause the
154+
computation to be run in a separate thread. Forking just allows the subsequent
155+
actions to execute without waiting for the forked computation to complete.
154156

155157
## Variables
156158

examples/src/Examples.purs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module Examples where
55

66
import Control.Monad.Aff
77
import Control.Monad.Aff.Var
8+
import Control.Monad.Aff.Par
9+
import Control.Apply((*>))
10+
import Control.Alt(Alt, (<|>))
811
import Control.Monad.Eff.Class(liftEff)
912
import Control.Monad.Eff.Exception(error)
1013
import Control.Monad.Error.Class(throwError)
@@ -31,6 +34,7 @@ module Examples where
3134

3235
type Test = forall e. Aff (trace :: Trace | e) Unit
3336
type TestVar = forall e. Aff (trace :: Trace, var :: VarFx | e) Unit
37+
type TestVarTime = forall e. Aff (trace :: Trace, var :: VarFx, time :: Time | e) Unit
3438

3539
test_sequencing :: forall e. Number -> Aff (trace :: Trace, time :: Time | e) Unit
3640
test_sequencing 0 = liftEff $ trace "Done"
@@ -63,6 +67,13 @@ module Examples where
6367
e <- attempt $ takeVar v
6468
liftEff $ either (const $ trace "Success: Killed var dead") (const $ trace "Failure: Oh noes, Var survived!") e
6569

70+
test_parRace :: TestVarTime
71+
test_parRace = do
72+
s <- runPar $ (Par (timeout 100 *> pure "Success: Early bird got the worm") <|>
73+
Par (timeout 1000 *> pure "Failure: Late bird got the worm"))
74+
liftEff $ trace s
75+
76+
6677
main = launchAff $ do
6778
liftEff $ trace "Testing sequencing"
6879
test_sequencing 3
@@ -81,3 +92,6 @@ module Examples where
8192

8293
liftEff $ trace "Testing killVar"
8394
test_killVar
95+
96+
liftEff $ trace "Testing Par (<|>)"
97+
test_parRace

0 commit comments

Comments
 (0)