timeout.js
This file
Path
lib/exit/timeout.js
20 lines · 779 bytes · JavaScript
Last changed by
Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
line 1why, one step back1import {setTimeout} from 'node:timers/promises';Add `ExecaError` and `ExecaSyncError` classes (#911)ehmickybefore adoptionfc01815
line 2why, one step back2import {DiscardedError} from '../return/cause.js';Split files (#837)ehmickybefore adoption672c2d7
lines 3–10why, one step back34export const validateTimeout = ({timeout}) => {5 if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) {6 throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);7 }8};910// `timeout` option handlingRename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 11why, one step back11export const throwOnTimeout = (subprocess, timeout, context, controller) => timeout === 0 || timeout === undefinedSplit files (#837)ehmickybefore adoption672c2d7
line 12why, one step back12 ? []Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 13why, one step back13 : [killAfterTimeout(subprocess, timeout, context, controller)];Split files (#837)ehmickybefore adoption672c2d7
line 14why, one step back14Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 15why, one step back15const killAfterTimeout = async (subprocess, timeout, context, {signal}) => {Split files (#837)ehmickybefore adoption672c2d7
lines 16–17why, one step back16 await setTimeout(timeout, undefined, {signal});17 context.timedOut = true;Rename `spawned` and `child process` to `subprocess` (#897)ehmickybefore adoption8fe2343
line 18why, one step back18 subprocess.kill();Split files (#837)ehmickybefore adoption672c2d7
lines 19–20why, one step back19 throw new DiscardedError();20};