File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,21 @@ module Examples where
6060 e <- attempt $ takeVar v
6161 either (const $ trace "Success : Killed queue dead ") (const $ trace "Failure : Oh noes , queue survived !") e
6262
63+ test_finally :: TestAVar _
64+ test_finally = do
65+ v <- makeVar
66+ finally
67+ (putVar v 0)
68+ (putVar v 2)
69+ apathize $ finally
70+ (throwError (error "poof!") *> putVar v 666) -- this putVar should not get executed
71+ (putVar v 40)
72+ n1 <- takeVar v
73+ n2 <- takeVar v
74+ n3 <- takeVar v
75+ trace $ if n1 + n2 + n3 == 42 then " Success: effects amount to 42."
76+ else " Failure: Expected 42."
77+
6378 test_parRace :: TestAVar _
6479 test_parRace = do
6580 s <- runPar (Par (later' 100 $ pure "Success: Early bird got the worm") <|>
@@ -134,6 +149,9 @@ module Examples where
134149 trace " Testing AVar killVar"
135150 test_killVar
136151
152+ trace " Testing finally"
153+ test_finally
154+
137155 trace " Testing Par (<|>)"
138156 test_parRace
139157
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ module Control.Monad.Aff
66 , attempt
77 , cancel
88 , cancelWith
9+ , finally
910 , forkAff
1011 , later
1112 , later'
You can’t perform that action at this time.
0 commit comments