mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
From tool-refactoring to sso. Makes the tool-refactoring/sso diff a little smaller (including removing some files from it entirely) and easier to review. Only took about five minutes to prepare, I swear this isn't a total waste of time :)
32 lines
680 B
JavaScript
32 lines
680 B
JavaScript
/// A simple interface to register functions to be called when the process
|
|
/// exits.
|
|
|
|
var _ = require('underscore');
|
|
|
|
var cleanup = exports;
|
|
_.extend(exports, {
|
|
_exitHandlers: [],
|
|
|
|
// register a function that will be called on SIGINT (e.g. Cmd-C on
|
|
// mac)
|
|
onExit: function (func) {
|
|
this._exitHandlers.push(func);
|
|
}
|
|
});
|
|
|
|
var runHandlers = function () {
|
|
var handlers = cleanup._exitHandlers;
|
|
cleanup._exitHandlers = [];
|
|
_.each(handlers, function (f) {
|
|
f();
|
|
});
|
|
};
|
|
|
|
process.on('exit', runHandlers);
|
|
_.each(['SIGINT', 'SIGHUP', 'SIGTERM'], function (sig) {
|
|
process.once(sig, function () {
|
|
runHandlers();
|
|
process.kill(process.pid, sig);
|
|
});
|
|
});
|