Last active
August 29, 2015 14:03
-
-
Save lakowske/8da4636aeac4fbc4e30f to your computer and use it in GitHub Desktop.
System resources and cooperative process exit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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