@@ -31,6 +31,7 @@ import Data.Maybe.Unsafe (fromJust)
31
31
import Data.StrMap (StrMap ())
32
32
import Data.StrMap as StrMap
33
33
import Node.Stream (Readable (), Writable ())
34
+ import Unsafe.Coerce (unsafeCoerce )
34
35
35
36
import Node.Platform (Platform ())
36
37
import Node.Platform as Platform
@@ -41,8 +42,8 @@ foreign import data PROCESS :: !
41
42
-- YOLO
42
43
foreign import process :: forall props . { | props }
43
44
44
- mutable :: forall eff a . a -> Eff eff a
45
- mutable = pure
45
+ mkEff :: forall eff a . ( Unit -> a ) -> Eff eff a
46
+ mkEff = unsafeCoerce
46
47
47
48
-- | Register a callback to be performed when the event loop empties, and
48
49
-- | Node.js is about to exit. Asynchronous calls can be made in the callback,
@@ -60,20 +61,25 @@ foreign import onExit :: forall eff. (Int -> Eff (process :: PROCESS | eff) Unit
60
61
-- | Install a handler for a particular signal.
61
62
foreign import onSignal :: forall eff . String -> Eff (process :: PROCESS | eff ) Unit -> Eff (process :: PROCESS | eff ) Unit
62
63
64
+ -- | Register a callback to run as soon as the current event loop runs to
65
+ -- | completion.
66
+ nextTick :: forall eff . Eff eff Unit -> Eff eff Unit
67
+ nextTick callback = mkEff \_ -> process.nextTick callback
68
+
63
69
-- | Get an array containing the command line arguments. Be aware
64
70
-- | that this can change over the course of the program.
65
71
argv :: forall eff . Eff (process :: PROCESS | eff ) (Array String )
66
- argv = mutable process.argv
72
+ argv = mkEff \_ -> process.argv
67
73
68
74
-- | Node-specific options passed to the `node` executable. Be aware that
69
75
-- | this can change over the course of the program.
70
76
execArgv :: forall eff . Eff (process :: PROCESS | eff ) (Array String )
71
- execArgv = mutable process.execArgv
77
+ execArgv = mkEff \_ -> process.execArgv
72
78
73
79
-- | The absolute pathname of the `node` executable that started the
74
80
-- | process.
75
81
execPath :: forall eff . Eff (process :: PROCESS | eff ) String
76
- execPath = mutable process.execPath
82
+ execPath = mkEff \_ -> process.execPath
77
83
78
84
-- | Change the current working directory of the process. If the current
79
85
-- | directory could not be changed, an exception will be thrown.
@@ -85,7 +91,7 @@ cwd = process.cwd
85
91
86
92
-- | Get a copy of the current environment.
87
93
getEnv :: forall eff . Eff (process :: PROCESS | eff ) (StrMap String )
88
- getEnv = mutable process.env
94
+ getEnv = mkEff \_ -> process.env
89
95
90
96
-- | Lookup a particular environment variable.
91
97
lookupEnv :: forall eff . String -> Eff (process :: PROCESS | eff ) (Maybe String )
0 commit comments