Skip to content

Commit eddb4e3

Browse files
committed
Unbreak
1 parent 9355fcd commit eddb4e3

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

src/Node/Process.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,45 @@
22
// module Node.Process
33

44
exports.process = process;
5+
6+
exports.onBeforeExit = function(callback) {
7+
return function() {
8+
process.on('beforeExit', callback);
9+
}
10+
};
11+
12+
exports.onExit = function(callback) {
13+
return function() {
14+
process.on('exit', function(code) {
15+
callback(code)();
16+
});
17+
};
18+
};
19+
20+
exports.onSignal = function(signal) {
21+
return function(callback) {
22+
return function() {
23+
process.on(signal, callback);
24+
};
25+
};
26+
};
27+
28+
exports.chdir = function(dir) {
29+
return function() {
30+
process.chdir(dir);
31+
};
32+
};
33+
34+
exports.setEnv = function(var_) {
35+
return function(val) {
36+
return function() {
37+
process.env[var_] = val;
38+
};
39+
};
40+
};
41+
42+
exports.exit = function(code) {
43+
return function() {
44+
process.exit(code);
45+
};
46+
};

src/Node/Process.purs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import Data.Maybe.Unsafe (fromJust)
3131
import Data.StrMap (StrMap())
3232
import Data.StrMap as StrMap
3333
import Node.Stream (Readable(), Writable())
34+
import Unsafe.Coerce (unsafeCoerce)
3435

3536
import Node.Platform (Platform())
3637
import Node.Platform as Platform
@@ -41,8 +42,8 @@ foreign import data PROCESS :: !
4142
-- YOLO
4243
foreign import process :: forall props. { | props }
4344

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
4647

4748
-- | Register a callback to be performed when the event loop empties, and
4849
-- | 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
6061
-- | Install a handler for a particular signal.
6162
foreign import onSignal :: forall eff. String -> Eff (process :: PROCESS | eff) Unit -> Eff (process :: PROCESS | eff) Unit
6263

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+
6369
-- | Get an array containing the command line arguments. Be aware
6470
-- | that this can change over the course of the program.
6571
argv :: forall eff. Eff (process :: PROCESS | eff) (Array String)
66-
argv = mutable process.argv
72+
argv = mkEff \_ -> process.argv
6773

6874
-- | Node-specific options passed to the `node` executable. Be aware that
6975
-- | this can change over the course of the program.
7076
execArgv :: forall eff. Eff (process :: PROCESS | eff) (Array String)
71-
execArgv = mutable process.execArgv
77+
execArgv = mkEff \_ -> process.execArgv
7278

7379
-- | The absolute pathname of the `node` executable that started the
7480
-- | process.
7581
execPath :: forall eff. Eff (process :: PROCESS | eff) String
76-
execPath = mutable process.execPath
82+
execPath = mkEff \_ -> process.execPath
7783

7884
-- | Change the current working directory of the process. If the current
7985
-- | directory could not be changed, an exception will be thrown.
@@ -85,7 +91,7 @@ cwd = process.cwd
8591

8692
-- | Get a copy of the current environment.
8793
getEnv :: forall eff. Eff (process :: PROCESS | eff) (StrMap String)
88-
getEnv = mutable process.env
94+
getEnv = mkEff \_ -> process.env
8995

9096
-- | Lookup a particular environment variable.
9197
lookupEnv :: forall eff. String -> Eff (process :: PROCESS | eff) (Maybe String)

0 commit comments

Comments
 (0)