@@ -2,14 +2,15 @@ module Test.Main where
2
2
3
3
import Prelude
4
4
import Control.Alt ((<|>))
5
- import Control.Monad.Aff (Aff , Canceler (..), ASYNC , nonCanceler , runAff , launchAff , makeAff , try , bracket , delay , forkAff , joinThread , killThread )
6
- import Control.Monad.Eff (Eff )
5
+ import Control.Monad.Aff (Aff , Canceler (..), nonCanceler , runAff , launchAff , makeAff , try , bracket , delay , forkAff , joinThread , killThread )
6
+ import Control.Monad.Eff (Eff , runPure )
7
7
import Control.Monad.Eff.Class (class MonadEff , liftEff )
8
8
import Control.Monad.Eff.Console (CONSOLE )
9
9
import Control.Monad.Eff.Console as Console
10
10
import Control.Monad.Eff.Exception (Error , EXCEPTION , throwException , error , message )
11
11
import Control.Monad.Eff.Ref (REF , Ref )
12
12
import Control.Monad.Eff.Ref as Ref
13
+ import Control.Monad.Eff.Ref.Unsafe (unsafeRunRef )
13
14
import Control.Monad.Error.Class (throwError )
14
15
import Control.Parallel (parallel , sequential )
15
16
import Data.Bifunctor (lmap )
@@ -21,7 +22,7 @@ import Data.Time.Duration (Milliseconds(..))
21
22
import Test.Assert (assert' , ASSERT )
22
23
23
24
type TestEffects eff = (assert ∷ ASSERT , console ∷ CONSOLE , ref ∷ REF , exception ∷ EXCEPTION | eff )
24
- type TestEff eff = Eff (TestEffects ( async ∷ ASYNC | eff ) )
25
+ type TestEff eff = Eff (TestEffects eff )
25
26
type TestAff eff = Aff (TestEffects eff )
26
27
27
28
newRef ∷ ∀ m eff a . MonadEff (ref ∷ REF | eff ) m ⇒ a → m (Ref a )
@@ -346,6 +347,23 @@ test_kill_parallel_alt = assert "kill/parallel/alt" do
346
347
_ ← try $ joinThread t2
347
348
eq " killedfookilledbardone" <$> readRef ref
348
349
350
+ test_mapThread ∷ ∀ eff . TestAff eff Unit
351
+ test_mapThread = assert " mapThread" do
352
+ ref ← newRef 0
353
+ let
354
+ mapFn a = runPure do
355
+ unsafeRunRef $ Ref .modifyRef ref (_ + 1 )
356
+ pure (a + 1 )
357
+ t1 ← forkAff do
358
+ delay (Milliseconds 10.0 )
359
+ pure 10
360
+ let
361
+ t2 = mapFn <$> t1
362
+ a ← joinThread t2
363
+ b ← joinThread t2
364
+ n ← readRef ref
365
+ pure (a == 11 && b == 11 && n == 1 )
366
+
349
367
main ∷ TestEff () Unit
350
368
main = do
351
369
test_pure
@@ -372,3 +390,4 @@ main = do
372
390
test_kill_parallel
373
391
test_parallel_alt
374
392
test_kill_parallel_alt
393
+ test_mapThread
0 commit comments