@@ -5,6 +5,7 @@ import Prelude
5
5
import Control.Alt ((<|>))
6
6
import Control.Monad.Aff (Aff , Canceler (..), runAff_ , launchAff , makeAff , try , bracket , generalBracket , delay , forkAff , suspendAff , joinFiber , killFiber , never , supervise , Error , error , message )
7
7
import Control.Monad.Aff.AVar (AVAR , makeEmptyVar , takeVar , putVar )
8
+ import Control.Monad.Aff.Compat as AC
8
9
import Control.Monad.Eff (Eff , runPure )
9
10
import Control.Monad.Eff.Class (class MonadEff , liftEff )
10
11
import Control.Monad.Eff.Console (CONSOLE )
@@ -13,6 +14,7 @@ import Control.Monad.Eff.Exception (throwException, EXCEPTION)
13
14
import Control.Monad.Eff.Ref (REF , Ref )
14
15
import Control.Monad.Eff.Ref as Ref
15
16
import Control.Monad.Eff.Ref.Unsafe (unsafeRunRef )
17
+ import Control.Monad.Eff.Timer (TIMER , setTimeout , clearTimeout )
16
18
import Control.Monad.Error.Class (throwError , catchError )
17
19
import Control.Parallel (parallel , sequential , parTraverse_ )
18
20
import Data.Array as Array
@@ -25,7 +27,7 @@ import Data.Time.Duration (Milliseconds(..))
25
27
import Data.Traversable (traverse )
26
28
import Test.Assert (assert' , ASSERT )
27
29
28
- type TestEffects eff = (assert ∷ ASSERT , console ∷ CONSOLE , ref ∷ REF , exception ∷ EXCEPTION , avar ∷ AVAR | eff )
30
+ type TestEffects eff = (assert ∷ ASSERT , console ∷ CONSOLE , ref ∷ REF , exception ∷ EXCEPTION , avar ∷ AVAR , timer ∷ TIMER | eff )
29
31
type TestEff eff = Eff (TestEffects eff )
30
32
type TestAff eff = Aff (TestEffects eff )
31
33
@@ -561,6 +563,24 @@ test_avar_order = assert "avar/order" do
561
563
joinFiber f1
562
564
eq " takenfoo" <$> readRef ref
563
565
566
+ test_efffn ∷ ∀ eff . TestAff eff Unit
567
+ test_efffn = assert " efffn" do
568
+ ref ← newRef " "
569
+ let
570
+ jsDelay ms = AC .fromEffFnAff $ AC.EffFnAff $ AC .mkEffFn2 \ke kc → do
571
+ tid ← setTimeout ms (AC .runEffFn1 kc unit)
572
+ pure $ AC.EffFnCanceler $ AC .mkEffFn3 \e cke ckc → do
573
+ clearTimeout tid
574
+ AC .runEffFn1 ckc unit
575
+ action = do
576
+ jsDelay 10
577
+ modifyRef ref (_ <> " done" )
578
+ f1 ← forkAff action
579
+ f2 ← forkAff action
580
+ killFiber (error " Nope." ) f2
581
+ delay (Milliseconds 20.0 )
582
+ eq " done" <$> readRef ref
583
+
564
584
test_parallel_stack ∷ ∀ eff . TestAff eff Unit
565
585
test_parallel_stack = assert " parallel/stack" do
566
586
ref ← newRef 0
@@ -609,6 +629,7 @@ main = do
609
629
test_parallel_mixed
610
630
test_kill_parallel_alt
611
631
test_avar_order
632
+ test_efffn
612
633
test_fiber_map
613
634
test_fiber_apply
614
635
-- Turn on if we decide to schedule forks
0 commit comments