Files
meteor/tools/tool-env/cleanup.js
Matheus Castro 170e5d3f6d Remove Fibers from meteor-tools:
- Adapt forkJoin and other files functions to correctly be awaited.
2022-12-22 14:09:27 -03:00

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);
});
});