clean up process events.

This commit is contained in:
Christopher Jeffrey 2015-01-31 12:24:55 -08:00
parent 27060d59af
commit a9153aeef5

View File

@ -17,6 +17,8 @@ var colors = require('./colors')
, program = require('./program')
, widget = exports;
var nextTick = global.setImmediate || process.nextTick.bind(process);
/**
* Node
*/
@ -352,12 +354,6 @@ function Screen(options) {
this.enter();
function reset() {
if (reset.done) return;
reset.done = true;
self.leave();
}
this._maxListeners = Infinity;
Screen.total++;
@ -366,10 +362,12 @@ function Screen(options) {
if (process.listeners('uncaughtException').length > Screen.total) {
return;
}
reset();
self.leave();
err = err || new Error('Uncaught Exception.');
console.error(err.stack ? err.stack + '' : err + '');
return process.exit(1);
nextTick(function() {
process.exit(1);
});
});
['SIGTERM', 'SIGINT', 'SIGQUIT'].forEach(function(signal) {
@ -377,12 +375,14 @@ function Screen(options) {
if (process.listeners(signal).length > Screen.total) {
return;
}
return process.exit(0);
nextTick(function() {
process.exit(0);
});
});
});
process.on('exit', function() {
reset();
self.leave();
});
this.on('newListener', function fn(type) {