/
spawn.js
36 lines (32 loc) · 859 Bytes
/
spawn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// vim: expandtab:ts=2:sw=2
function _writeSync(stream, str, cb) {
var flushed = stream.write(str);
if (flushed) {
return cb(null);
}
stream.once('drain', function _flushed() {
cb(null);
});
}
module.exports = {
graceful: false,
out: function (str, cb) {
cb = cb || this.exit;
_writeSync(process.stdout, str, cb);
},
err: function (errOrStr, cb) {
cb = cb || this.exit;
if (!this.graceful) _writeSync(process.stderr, (errOrStr instanceof Error) ? errOrStr.toString() : errOrStr, cb);
else cb();
},
fail: function (errOrStr, cb) {
cb = cb || this.exit;
_writeSync(process.stderr, (errOrStr instanceof Error) ? errOrStr.toString() : errOrStr, cb);
},
exit: function (code) {
process.exit(code || 0);
},
kill: function (signal) {
process.kill(process.pid, signal || 'SIGINT');
}
};