Skip to content
Myr

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 file

Take 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 back
1import {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 back
6 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 back
8 }
9};

Fix invalid `timeout` and `forceKillAfterDelay` valuesSindre Sorhusbefore adoptiond9a5689

lines 10–15why, one step back
10
11// 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 back
16
17// Fails when the `timeout` option is exceeded

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 18why, one step back
18export const throwOnTimeout = (kill, timeout, context, controller) => timeout === 0 || timeout === undefined

Improve `readme.md` (#999)ehmickybefore adoptionaca3db3

line 19why, one step back
19 ? []

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 20why, one step back
20 : [killAfterTimeout(kill, timeout, context, controller)];

Improve `readme.md` (#999)ehmickybefore adoptionaca3db3

line 21why, one step back
21

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 22why, one step back
22const killAfterTimeout = async (kill, timeout, context, {signal}) => {

Improve `readme.md` (#999)ehmickybefore adoptionaca3db3

line 23why, one step back
23 await setTimeout(timeout, undefined, {signal});

Add `gracefulCancel` option (#1109)ehmickybefore adoptiond8190e5

line 24why, one step back
24 context.terminationReason ??= 'timeout';

Add `nodeChildProcess` to subprocess promises and make the subprocess a normal promise (#1255)Sindre Sorhusbefore adoptionade74bf

line 25why, one step back
25 kill();

Improve `readme.md` (#999)ehmickybefore adoptionaca3db3

lines 26–27why, one step back
26 throw new DiscardedError();
27};