improve process.exit() workaround (#2741)

- use public API
- fix issue with Node.js 0.10 on WIndows
This commit is contained in:
Alex Lam S.L
2018-01-07 17:53:50 +08:00
committed by GitHub
parent 1ee8be8d91
commit 9809567dfc
4 changed files with 18 additions and 15 deletions

15
tools/exit.js Normal file
View File

@@ -0,0 +1,15 @@
// workaround for tty output truncation upon process.exit()
var exit = process.exit;
process.exit = function() {
var args = [].slice.call(arguments);
process.once("uncaughtException", function() {
(function callback() {
if (process.stdout.bufferSize || process.stderr.bufferSize) {
setImmediate(callback);
} else {
exit.apply(process, args);
}
})();
});
throw exit;
};