mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
20 lines
451 B
JavaScript
20 lines
451 B
JavaScript
// A simple interface to register functions to be called when the process exits.
|
|
|
|
const exitHandlers = [];
|
|
|
|
export function onExit(func) {
|
|
exitHandlers.push(func);
|
|
}
|
|
|
|
async function runHandlers() {
|
|
await Promise.all(exitHandlers.splice(0).map(f => f()));
|
|
}
|
|
|
|
process.on('exit', runHandlers);
|
|
['SIGINT', 'SIGHUP', 'SIGTERM'].forEach((sig) => {
|
|
process.once(sig, async () => {
|
|
await runHandlers();
|
|
process.kill(process.pid, sig);
|
|
});
|
|
});
|