visop
Version:
A simple CLI for scaffolding visible operation projects.
44 lines (36 loc) • 1.26 kB
JavaScript
// Object to capture process exits and call app specific cleanup function
function noOp() {};
exports.Cleanup = function Cleanup(callback) {
// attach user callback to the process event emitter
// if no callback, it will still exit gracefully on Ctrl-C
callback = callback || noOp;
process.on('cleanup',callback);
// do app specific cleaning before exiting
process.on('exit', function () {
process.emit('cleanup');
});
// catch ctrl+c event and exit normally
process.on('SIGINT', function () {
console.log('Ctrl-C...');
process.exit(2);
});
//catch uncaught exceptions, trace, then exit normally
process.on('uncaughtException', function(e) {
console.log('Uncaught Exception...');
console.log(e.stack);
process.exit(99);
});
// process.on('uncaughtException', function (err) {
// console.error("uncaughtException ERROR");
// if (typeof err === 'object') {
// if (err.message) {
// console.error('ERROR: ' + err.message)
// }
// if (err.stack) {
// console.error(err.stack);
// }
// } else {
// console.error('argument is not an object');
// }
// });
};