@@ -4,19 +4,19 @@ import Prelude
44
55import Control.Alt ((<|>))
66import 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 )
88import Control.Monad.Aff.AVar (AVAR , makeVar , makeVar' , putVar , modifyVar , takeVar , killVar )
99import Control.Monad.Aff.Console (log )
1010import Control.Monad.Aff.Par (Par (..), runPar )
1111import Control.Monad.Cont.Class (callCC )
1212import Control.Monad.Eff (Eff )
1313import Control.Monad.Eff.Console (CONSOLE )
14- import Control.Monad.Eff.Exception (EXCEPTION , throwException , error )
14+ import Control.Monad.Eff.Exception (EXCEPTION , throwException , error , message )
1515import Control.Monad.Error.Class (throwError )
1616import Control.Monad.Rec.Class (tailRecM )
17-
18- import Data.Either (Either (..), either )
17+ import Data.Either (Either (..), either , fromLeft , fromRight )
1918import Data.Unfoldable (replicate )
19+ import Partial.Unsafe (unsafePartial )
2020
2121type Test a = forall e . Aff (console :: CONSOLE | e ) a
2222type TestAVar a = forall e . Aff (console :: CONSOLE , avar :: AVAR | e ) a
@@ -30,6 +30,21 @@ test_sequencing n = do
3030 later' 100 (log (show (n / 10 ) <> " seconds left" ))
3131 test_sequencing (n - 1 )
3232
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+
3348test_pure :: Test Unit
3449test_pure = do
3550 pure unit
@@ -60,7 +75,6 @@ test_killFirstForked = do
6075 b <- c `cancel` (error " Just die" )
6176 log (if b then " Success: Killed first forked" else " Failure: Couldn't kill first forked" )
6277
63-
6478test_killVar :: TestAVar Unit
6579test_killVar = do
6680 v <- makeVar
@@ -180,6 +194,9 @@ main = runAff throwException (const (pure unit)) $ do
180194 log " Testing pure"
181195 test_pure
182196
197+ log " Testing makeAff"
198+ test_makeAff
199+
183200 log " Testing attempt"
184201 test_attempt
185202
0 commit comments