@@ -4,14 +4,14 @@ import Prelude
4
4
5
5
import Control.Alt ((<|>))
6
6
import Control.Apply ((*>))
7
- import Control.Monad.Aff (Aff (), runAff , later , later' , forkAff , forkAll , Canceler (..), cancel , attempt , finally , apathize )
7
+ import Control.Monad.Aff (Aff (), runAff , makeAff , later , later' , forkAff , forkAll , Canceler (..), cancel , attempt , finally , apathize )
8
8
import Control.Monad.Aff.AVar (AVAR (), makeVar , makeVar' , putVar , modifyVar , takeVar , killVar )
9
9
import Control.Monad.Aff.Console (log )
10
10
import Control.Monad.Aff.Par (Par (..), runPar )
11
11
import Control.Monad.Cont.Class (callCC )
12
12
import Control.Monad.Eff (Eff ())
13
13
import Control.Monad.Eff.Console (CONSOLE ())
14
- import Control.Monad.Eff.Exception (EXCEPTION (), throwException , error )
14
+ import Control.Monad.Eff.Exception (EXCEPTION (), throwException , error , message )
15
15
import Control.Monad.Error.Class (throwError )
16
16
import Control.Monad.Rec.Class (tailRecM )
17
17
@@ -27,6 +27,21 @@ test_sequencing n = do
27
27
later' 100 (log (show (n / 10 ) ++ " seconds left" ))
28
28
test_sequencing (n - 1 )
29
29
30
+ foreign import synchronousUnexpectedThrowError :: forall e . Eff e Unit
31
+
32
+ test_makeAff :: Test Unit
33
+ test_makeAff = do
34
+ s <- attempt $ makeAff \reject resolve -> resolve " ok"
35
+ log $ " makeAff success is " ++ (\(Right s') -> s') s
36
+
37
+ asyncF <- attempt $ makeAff \reject resolve -> reject (error " ok" )
38
+ log $ " makeAff asynchronous failure is " ++ message ((\(Left f) -> f) asyncF)
39
+
40
+ asyncF <- attempt $ makeAff \reject resolve -> synchronousUnexpectedThrowError
41
+ log $ " makeAff synchronous failure is " ++ message ((\(Left f) -> f) asyncF)
42
+
43
+ log " Success: makeAff is ok"
44
+
30
45
test_pure :: Test Unit
31
46
test_pure = do
32
47
pure unit
@@ -57,7 +72,6 @@ test_killFirstForked = do
57
72
b <- c `cancel` (error " Just die" )
58
73
log (if b then " Success: Killed first forked" else " Failure: Couldn't kill first forked" )
59
74
60
-
61
75
test_killVar :: TestAVar Unit
62
76
test_killVar = do
63
77
v <- makeVar
@@ -156,6 +170,9 @@ main = runAff throwException (const (pure unit)) $ do
156
170
log " Testing pure"
157
171
test_pure
158
172
173
+ log " Testing makeAff"
174
+ test_makeAff
175
+
159
176
log " Testing attempt"
160
177
test_attempt
161
178
0 commit comments