UNPKG

@mail-core/cli

Version:

Инструментарий для написания cli-скриптов

41 lines 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addProcessExitListener = void 0; function addProcessExitListener(handler) { const listeners = []; const add = (...args) => { listeners.push(args); process.on(args[0], args[1]); }; ['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2'].forEach((type) => { add(type, (coreOrSignal) => { if (type === 'exit') { handler({ type: 'exit', code: coreOrSignal, }); } else { handler({ type: type === 'SIGINT' ? 'break' : 'kill', signal: coreOrSignal, }); } }); }); add('uncaughtException', (reason) => { handler({ type: 'uncaughtException', reason, }); }); return function removeExitListener() { listeners.forEach(([type, listener]) => { process.off(type, listener); }); listeners.length = 0; ; }; } exports.addProcessExitListener = addProcessExitListener; //# sourceMappingURL=exit.js.map