Skip to content

Instantly share code, notes, and snippets.

@lakowske
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lakowske/8da4636aeac4fbc4e30f to your computer and use it in GitHub Desktop.
Save lakowske/8da4636aeac4fbc4e30f to your computer and use it in GitHub Desktop.
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