timeout.js
This file
Path
lib/terminate/timeout.js
33 lines · 1.2 KiB · JavaScript
Last changed by
Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 1–2why, one step back1import {setTimeout} from 'node:timers/promises';2import {DiscardedError} from '../return/final-error.js';Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
line 3why, one step back3import {getTypeName} from '../utils/type-name.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 4–6why, one step back45// Validate `timeout` option6export const validateTimeout = ({timeout}) => {Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
lines 7–8why, one step back7 if (timeout !== undefined) {8 validateDelay(timeout, 'timeout');100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 9–10why, one step back9 }10};Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
line 11why, one step back11Fix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
lines 12–18why, one step back12// Used by the `timeout` and `forceKillAfterDelay` options.13// Fractional numbers are excluded since `spawnSync()` requires an integer `timeout`.14export const validateDelay = (delay, optionName) => {15 if (!Number.isInteger(delay) || delay < 0 || delay > MAX_DELAY) {16 throw new TypeError(`Expected the \`${optionName}\` option to be a non-negative integer up to ${MAX_DELAY}, got \`${delay}\` (${getTypeName(delay)})`);17 }18};Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689
lines 19–20why, one step back1920// Timers fire right away when their delay is larger than thisFix wrong-typed options and arguments being silently ignored or coercedSindre Sorhusbefore adoptionb57d643
line 21why, one step back21const MAX_DELAY = (2 ** 31) - 1;100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 22–23why, one step back2223// Fails when the `timeout` option is exceededAdd `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 24why, one step back24export const throwOnTimeout = (kill, timeout, context, controller) => timeout === 0 || timeout === undefined100% test coverage (#1018)ehmickybefore adoption9f65b86
line 25why, one step back25 ? []Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 26why, one step back26 : [killAfterTimeout(kill, timeout, context, controller)];100% test coverage (#1018)ehmickybefore adoption9f65b86
line 27why, one step back27Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 28why, one step back28const killAfterTimeout = async (kill, timeout, context, {signal}) => {100% test coverage (#1018)ehmickybefore adoption9f65b86
line 29why, one step back29 await setTimeout(timeout, undefined, {signal});Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5
line 30why, one step back30 context.terminationReason ??= 'timeout';Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf
line 31why, one step back31 kill();100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 32–33why, one step back32 throw new DiscardedError();33};