timeout.js
This file
Path
lib/terminate/timeout.js
27 lines · 1.1 KiB · JavaScript
Last changed by
Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
History of this fileTake it
The walk stopped after 200 commits: lines older than aca3db3 point at it.
Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 1–5why, one step back1import {setTimeout} from 'node:timers/promises';2import {DiscardedError} from '../return/final-error.js';34// Validate `timeout` option5export const validateTimeout = ({timeout}) => {Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
lines 6–7why, one step back6 if (timeout !== undefined && !isValidDelay(timeout)) {7 throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer up to ${MAX_DELAY}, got \`${timeout}\` (${typeof timeout})`);Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 8–9why, one step back8 }9};Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
lines 10–15why, one step back1011// Fractional numbers are excluded since `spawnSync()` requires an integer `timeout`12export const isValidDelay = delay => Number.isInteger(delay) && delay >= 0 && delay <= MAX_DELAY;1314// Timers fire right away when their delay is larger than this15export const MAX_DELAY = (2 ** 31) - 1;Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 16–17why, one step back1617// Fails when the `timeout` option is exceededAdd `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 18why, one step back18export const throwOnTimeout = (kill, timeout, context, controller) => timeout === 0 || timeout === undefinedImprove `readme.md` (#999)ehmickybefore adoptionaca3db3
line 19why, one step back19 ? []Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 20why, one step back20 : [killAfterTimeout(kill, timeout, context, controller)];Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 21why, one step back21Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 22why, one step back22const killAfterTimeout = async (kill, timeout, context, {signal}) => {Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
line 23why, one step back23 await setTimeout(timeout, undefined, {signal});Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 24why, one step back24 context.terminationReason ??= 'timeout';Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 25why, one step back25 kill();Improve `readme.md` (#999)ehmickybefore adoptionaca3db3
lines 26–27why, one step back26 throw new DiscardedError();27};