cleanup.js
This file
Path
lib/terminate/cleanup.js
16 lines · 411 bytes · JavaScript
Last changed by
Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
History of this fileTake it
1234567891011121314151617import {addAbortListener} from 'node:events';import {onExit} from 'signal-exit';
// If the `cleanup` option is used, call `subprocess.kill()` when the parent process exitsexport const cleanupOnExit = (kill, {cleanup, detached}, {signal}) => { if (!cleanup || detached) { return; }
const removeExitHandler = onExit(() => { kill(); }); addAbortListener(signal, () => { removeExitHandler(); });};