Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
System resources and cooperative process exit
(function(COMPOSITE) {
//Load our dependencies
var util = require('util');
var events = require('events');
var RSVP = require('rsvp');
COMPOSITE.Process = new events.EventEmitter;
//Before we get interrupted, close resources
process.on('SIGINT', function() {
var toShutdown = []
var processFn = function (shutdownProcess) {
toShutdown.push(shutdownProcess)
}
COMPOSITE.Process.emit('exit', processFn);
RSVP.all(toShutdown).then(function() {
console.log('everything shutdown...exiting');
process.exit();
})
})
})(COMPOSITE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment