Files
meteor/tools/cleanup.js
David Greenspan eeab7df2d1 Don’t yield in cleanup.onExit handlers
Temp dirs were not getting cleaned up on ctrl-C, including ~100 MB temp
dirs created by test-packages.

Wrapping cleanup handlers in noYieldsAllowed automatically causes sync
versions of fs calls to be used when files.rm_recursive is called.
2015-01-10 16:42:54 -08:00

39 lines
871 B
JavaScript

/// A simple interface to register functions to be called when the process
/// exits.
var _ = require('underscore');
var Fiber = require("fibers");
var fiberHelpers = require('./fiber-helpers.js');
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 () {
Fiber(function () {
fiberHelpers.noYieldsAllowed(function () {
var handlers = cleanup._exitHandlers;
cleanup._exitHandlers = [];
_.each(handlers, function (f) {
f();
});
});
}).run();
};
process.on('exit', runHandlers);
_.each(['SIGINT', 'SIGHUP', 'SIGTERM'], function (sig) {
process.once(sig, function () {
runHandlers();
process.kill(process.pid, sig);
});
});