mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
27 lines
582 B
JavaScript
27 lines
582 B
JavaScript
// A simple interface to register functions to be called when the process exits.
|
|
|
|
import { noYieldsAllowed } from "../utils/fiber-helpers.js";
|
|
|
|
const exitHandlers = [];
|
|
|
|
export function onExit(func) {
|
|
exitHandlers.push(func);
|
|
}
|
|
|
|
function runHandlers() {
|
|
noYieldsAllowed(() => {
|
|
// Empty and execute all queued exit handlers.
|
|
exitHandlers.splice(0).forEach((f) => {
|
|
f();
|
|
});
|
|
});
|
|
}
|
|
|
|
process.on('exit', runHandlers);
|
|
['SIGINT', 'SIGHUP', 'SIGTERM'].forEach((sig) => {
|
|
process.once(sig, () => {
|
|
runHandlers();
|
|
process.kill(process.pid, sig);
|
|
});
|
|
});
|