automatically deal with custom process events. fixes #100.

This commit is contained in:
Christopher Jeffrey 2015-01-31 12:19:00 -08:00
parent 127ae12c1b
commit 27060d59af

View File

@ -360,16 +360,25 @@ function Screen(options) {
this._maxListeners = Infinity;
if (this.options.handleUncaughtExceptions !== false) {
process.on('uncaughtException', function(err) {
reset();
if (err) console.error(err.stack ? err.stack + '' : err + '');
return process.exit(1);
});
}
Screen.total++;
process.on('SIGTERM', function() {
return process.exit(0);
process.on('uncaughtException', function(err) {
if (process.listeners('uncaughtException').length > Screen.total) {
return;
}
reset();
err = err || new Error('Uncaught Exception.');
console.error(err.stack ? err.stack + '' : err + '');
return process.exit(1);
});
['SIGTERM', 'SIGINT', 'SIGQUIT'].forEach(function(signal) {
process.on(signal, function() {
if (process.listeners(signal).length > Screen.total) {
return;
}
return process.exit(0);
});
});
process.on('exit', function() {
@ -398,6 +407,8 @@ function Screen(options) {
Screen.global = null;
Screen.total = 0;
Screen.prototype.__proto__ = Node.prototype;
Screen.prototype.type = 'screen';