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
60
60
e <- attempt $ takeVar v
61
61
either (const $ trace "Success : Killed queue dead ") (const $ trace "Failure : Oh noes , queue survived !") e
62
62
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
+
63
78
test_parRace :: TestAVar _
64
79
test_parRace = do
65
80
s <- runPar (Par (later' 100 $ pure "Success: Early bird got the worm") <|>
@@ -134,6 +149,9 @@ module Examples where
134
149
trace " Testing AVar killVar"
135
150
test_killVar
136
151
152
+ trace " Testing finally"
153
+ test_finally
154
+
137
155
trace " Testing Par (<|>)"
138
156
test_parRace
139
157
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ module Control.Monad.Aff
6
6
, attempt
7
7
, cancel
8
8
, cancelWith
9
+ , finally
9
10
, forkAff
10
11
, later
11
12
, later'
You can’t perform that action at this time.
0 commit comments