From 27060d59aff3c70f32f2f669b0827e02d3b0cbf9 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 31 Jan 2015 12:19:00 -0800 Subject: [PATCH] automatically deal with custom process events. fixes #100. --- lib/widget.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/widget.js b/lib/widget.js index c413996..7b9e5c0 100644 --- a/lib/widget.js +++ b/lib/widget.js @@ -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';