kill.js
This file
Path
lib/kill.js
76 lines · 2.4 KiB · JavaScript
Last changed by
Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
History of this fileTake it
The walk stopped after 200 commits: lines older than 408904b point at it.
Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 1why, one step back1import os from 'node:os';Improve graceful exit (#714)ehmickybefore adoption5eeaab5
line 2why, one step back2import {setTimeout} from 'node:timers/promises';Upgrade `signal-exit` to v4 (#570)ehmickybefore adoption468fbe1
line 3why, one step back3import {onExit} from 'signal-exit';Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 4–6why, one step back45const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5;6Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34
line 7why, one step back7// Monkey-patches `childProcess.kill()` to add `forceKillAfterDelay` behaviorImprove `killSignal` option (#728)ehmickybefore adoptioncf36c1d
line 8why, one step back8export const spawnedKill = (kill, {forceKillAfterDelay, killSignal}, controller, signal = killSignal) => {Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
line 9why, one step back9 const killResult = kill(signal);Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
line 10why, one step back10 setKillTimeout({kill, signal, forceKillAfterDelay, killSignal, killResult, controller});Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 11–13why, one step back11 return killResult;12};13Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
lines 14–15why, one step back14const setKillTimeout = async ({kill, signal, forceKillAfterDelay, killSignal, killResult, controller}) => {15 if (!shouldForceKill(signal, forceKillAfterDelay, killSignal, killResult)) {Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 16–18why, one step back16 return;17 }18Improve graceful exit (#714)ehmickybefore adoption5eeaab5
line 19why, one step back19 try {Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34
line 20why, one step back20 await setTimeout(forceKillAfterDelay, undefined, {signal: controller.signal});Improve graceful exit (#714)ehmickybefore adoption5eeaab5
lines 21–22why, one step back21 kill('SIGKILL');22 } catch {}Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 23–24why, one step back23};24Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
lines 25–28why, one step back25const shouldForceKill = (signal, forceKillAfterDelay, killSignal, killResult) =>26 normalizeSignal(signal) === normalizeSignal(killSignal)27 && forceKillAfterDelay !== false28 && killResult;Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
line 29why, one step back29Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
lines 30–32why, one step back30const normalizeSignal = signal => typeof signal === 'string'31 ? os.constants.signals[signal.toUpperCase()]32 : signal;Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
line 33why, one step back33Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34
lines 34–36why, one step back34export const normalizeForceKillAfterDelay = forceKillAfterDelay => {35 if (forceKillAfterDelay === false) {36 return forceKillAfterDelay;Refactor `childProcess.kill()` to use `async/await` (#651)ehmickybefore adoption7701e9e
lines 37–38why, one step back37 }38Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34
line 39why, one step back39 if (forceKillAfterDelay === true) {Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 40–42why, one step back40 return DEFAULT_FORCE_KILL_TIMEOUT;41 }42Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34
lines 43–44why, one step back43 if (!Number.isFinite(forceKillAfterDelay) || forceKillAfterDelay < 0) {44 throw new TypeError(`Expected the \`forceKillAfterDelay\` option to be a non-negative integer, got \`${forceKillAfterDelay}\` (${typeof forceKillAfterDelay})`);Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 45–46why, one step back45 }46Rename `forceKillAfterTimeout` to `forceKillAfterDelay` (#723)ehmickybefore adoption0ff8b34
line 47why, one step back47 return forceKillAfterDelay;Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 48–49why, one step back48};49Improve `killSignal` option (#728)ehmickybefore adoptioncf36c1d
line 50why, one step back50const killAfterTimeout = async (timeout, context, controller) => {Improve graceful exit (#714)ehmickybefore adoption5eeaab5
line 51why, one step back51 await setTimeout(timeout, undefined, {signal: controller.signal});Improve process termination (#724)ehmickybefore adoption1c48d37
line 52why, one step back52 context.timedOut = true;Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 53why, one step back53 throw new Error('Timed out');Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 54–56why, one step back54};5556// `timeout` option handlingImprove `killSignal` option (#728)ehmickybefore adoptioncf36c1d
lines 57–59why, one step back57export const throwOnTimeout = (timeout, context, controller) => timeout === 0 || timeout === undefined58 ? []59 : [killAfterTimeout(timeout, context, controller)];Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
line 60why, one step back60Require Node.js 12.20 and move to ESM (#478)Minh Nguyenbefore adoption7707880
line 61why, one step back61export const validateTimeout = ({timeout}) => {Fix `timeout` option validation (#463)ehmickybefore adoption427c5c2
lines 62–66why, one step back62 if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {63 throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);64 }65};66Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
line 67why, one step back67// `cleanup` option handlingImprove graceful exit (#714)ehmickybefore adoption5eeaab5
line 68why, one step back68export const cleanupOnExit = (spawned, cleanup, detached) => {Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
line 69why, one step back69 if (!cleanup || detached) {Use `async/await` instead of direct `Promise` manipulation (#659)ehmickybefore adoption7122767
line 70why, one step back70 return;Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 71–72why, one step back71 }72Improve graceful exit (#714)ehmickybefore adoption5eeaab5
line 73why, one step back73 return onExit(() => {Clean up outdated code in tests (#405)fisker Cheungbefore adoption408904b
lines 74–76why, one step back74 spawned.kill();75 });76};