hfs
Version:
HTTP File Server
21 lines (20 loc) • 682 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.onProcessExit = onProcessExit;
exports.onFirstEvent = onFirstEvent;
const cbs = new Set();
function onProcessExit(cb) {
cbs.add(cb);
return () => cbs.delete(cb);
}
onFirstEvent(process, ['exit', 'SIGQUIT', 'SIGTERM', 'SIGINT', 'SIGHUP'], signal => Promise.allSettled(Array.from(cbs).map(cb => cb(signal))).then(() => process.exit(0)));
function onFirstEvent(emitter, events, cb) {
let already = false;
for (const e of events)
emitter.once(e, (...args) => {
if (already)
return;
already = true;
cb(...args);
});
}
;