Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit d84ec46

Browse files
committed
Test Node.js event loop exit prevention
1 parent 96810fd commit d84ec46

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

spago-dev.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ conf //
2020
, "console"
2121
, "partial"
2222
, "unsafe-coerce"
23+
, "control"
2324
]
2425
, packages = packages_dev
2526
}

test/Main4.purs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
-- | How to test:
2+
-- |
3+
-- | ```
4+
-- | spago -x spago-dev.dhall test --main Test4
5+
-- | ```
6+
-- |
7+
-- | This is a test that `readSome` will prevent the Node.js event
8+
-- | loop from exiting.
9+
module Test4 where
10+
11+
import Prelude
12+
13+
import Control.Alt (alt)
14+
import Data.Either (Either(..))
15+
import Effect (Effect)
16+
import Effect.Aff (Error, Milliseconds(..), delay, parallel, runAff_, sequential)
17+
import Effect.Class.Console as Console
18+
import Node.Process (stdin)
19+
import Node.Stream.Aff (readSome)
20+
import Partial.Unsafe (unsafePartial)
21+
import Test.Spec (describe, it)
22+
import Test.Spec.Reporter (consoleReporter)
23+
import Test.Spec.Runner (runSpec)
24+
import Unsafe.Coerce (unsafeCoerce)
25+
26+
completion :: Either Error (Effect Unit) -> Effect Unit
27+
completion = case _ of
28+
Left e -> Console.error (unsafeCoerce e)
29+
Right f -> f
30+
31+
32+
main :: Effect Unit
33+
main = unsafePartial $ do
34+
runAff_ completion do
35+
runSpec [consoleReporter] do
36+
describe "Node.Stream.Aff" do
37+
it "reads 1" do
38+
sequential $ alt
39+
do
40+
parallel $ void $ readSome stdin
41+
do
42+
parallel $ delay (Milliseconds 500.0)
43+
pure (pure unit)

0 commit comments

Comments
 (0)