@@ -4,19 +4,19 @@ 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
-
18
- import Data.Either (Either (..), either )
17
+ import Data.Either (Either (..), either , fromLeft , fromRight )
19
18
import Data.Unfoldable (replicate )
19
+ import Partial.Unsafe (unsafePartial )
20
20
21
21
type Test a = forall e . Aff (console :: CONSOLE | e ) a
22
22
type TestAVar a = forall e . Aff (console :: CONSOLE , avar :: AVAR | e ) a
@@ -30,6 +30,21 @@ test_sequencing n = do
30
30
later' 100 (log (show (n / 10 ) <> " seconds left" ))
31
31
test_sequencing (n - 1 )
32
32
33
+ foreign import synchronousUnexpectedThrowError :: forall e . Eff e Unit
34
+
35
+ test_makeAff :: Test Unit
36
+ test_makeAff = unsafePartial do
37
+ s <- attempt $ makeAff \reject resolve -> resolve " ok"
38
+ log $ " makeAff success is " <> fromRight s
39
+
40
+ asyncF <- attempt $ makeAff \reject resolve -> reject (error " ok" )
41
+ log $ " makeAff asynchronous failure is " <> message (fromLeft asyncF)
42
+
43
+ asyncF <- attempt $ makeAff \reject resolve -> synchronousUnexpectedThrowError
44
+ log $ " makeAff synchronous failure is " <> message (fromLeft asyncF)
45
+
46
+ log " Success: makeAff is ok"
47
+
33
48
test_pure :: Test Unit
34
49
test_pure = do
35
50
pure unit
@@ -60,7 +75,6 @@ test_killFirstForked = do
60
75
b <- c `cancel` (error " Just die" )
61
76
log (if b then " Success: Killed first forked" else " Failure: Couldn't kill first forked" )
62
77
63
-
64
78
test_killVar :: TestAVar Unit
65
79
test_killVar = do
66
80
v <- makeVar
@@ -180,6 +194,9 @@ main = runAff throwException (const (pure unit)) $ do
180
194
log " Testing pure"
181
195
test_pure
182
196
197
+ log " Testing makeAff"
198
+ test_makeAff
199
+
183
200
log " Testing attempt"
184
201
test_attempt
185
202
0 commit comments