Skip to content

Commit c89e878

Browse files
committed
some bugs fixed
1 parent 8a91c4e commit c89e878

File tree

3 files changed

+298
-137
lines changed

3 files changed

+298
-137
lines changed

examples/src/Examples.purs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ module Examples where
3838
apathize $ throwError (error "Oh noes!")
3939
liftEff $ trace "Success: Exceptions don't stop the apathetic"
4040

41-
test_putTakeQueue :: TestAVar
42-
test_putTakeQueue = do
41+
test_putTakeVar :: TestAVar
42+
test_putTakeVar = do
4343
v <- makeVar
4444
forkAff (later $ putVar v 1.0)
4545
a <- takeVar v
@@ -52,8 +52,8 @@ module Examples where
5252
liftEff $ trace (if b then "Success: Killed first forked" else "Failure: Couldn't kill first forked")
5353

5454

55-
test_killQueue :: TestAVar
56-
test_killQueue = do
55+
test_killVar :: TestAVar
56+
test_killVar = do
5757
v <- makeVar
5858
killVar v (error "DOA")
5959
e <- attempt $ takeVar v
@@ -77,6 +77,31 @@ module Examples where
7777
Par (later' 200 $ throwError (error ("Oh noes!"))))
7878
liftEff $ either (const $ trace "Success: Killing both kills it dead") (const $ trace "Failure: It's alive!!!") e
7979

80+
test_semigroupCanceler :: Test
81+
test_semigroupCanceler =
82+
let
83+
c = Canceler (const (pure true)) <> Canceler (const (pure true))
84+
in do
85+
v <- cancel c (error "CANCEL")
86+
liftEff $ trace (if v then "Success: Canceled semigroup composite canceler"
87+
else "Failure: Could not cancel semigroup composite canceler")
88+
89+
test_cancelLater :: TestAVar
90+
test_cancelLater = do
91+
c <- forkAff $ (do pure "Binding"
92+
_ <- later' 100 $ liftEff $ trace ("Failure: Later was not canceled!")
93+
pure "Binding")
94+
v <- cancel c (error "Cause")
95+
liftEff $ trace (if v then "Success: Canceled later" else "Failure: Did not cancel later")
96+
97+
test_cancelPar :: TestAVar
98+
test_cancelPar = do
99+
c <- forkAff <<< runPar $ Par (later' 100 $ liftEff $ trace "Failure: #1 should not get through") <|>
100+
Par (later' 100 $ liftEff $ trace "Failure: #2 should not get through")
101+
v <- c `cancel` (error "Must cancel")
102+
liftEff $ trace (if v then "Success: Canceling composite of two Par succeeded"
103+
else "Failure: Canceling composite of two Par failed")
104+
80105
main = launchAff $ do
81106
liftEff $ trace "Testing sequencing"
82107
test_sequencing 3
@@ -90,17 +115,23 @@ module Examples where
90115
liftEff $ trace "Testing later"
91116
later $ liftEff $ trace "Success: It happened later"
92117

118+
liftEff $ trace "Testing kill of later"
119+
test_cancelLater
120+
93121
liftEff $ trace "Testing kill of first forked"
94122
test_killFirstForked
95123

96124
liftEff $ trace "Testing apathize"
97125
test_apathize
98126

99-
liftEff $ trace "Testing Queue - putVar, takeVar"
100-
test_putTakeQueue
127+
liftEff $ trace "Testing semigroup canceler"
128+
test_semigroupCanceler
101129

102-
liftEff $ trace "Testing killVar"
103-
test_killQueue
130+
liftEff $ trace "Testing AVar - putVar, takeVar"
131+
test_putTakeVar
132+
133+
liftEff $ trace "Testing AVar killVar"
134+
test_killVar
104135

105136
liftEff $ trace "Testing Par (<|>)"
106137
test_parRace
@@ -111,4 +142,7 @@ module Examples where
111142
liftEff $ trace "Testing Par (<|>) - kill two"
112143
test_parRaceKill2
113144

145+
liftEff $ trace "Testing cancel of Par (<|>)"
146+
test_cancelPar
147+
114148
liftEff $ trace "Done testing"

0 commit comments

Comments
 (0)