timeout.js
This file
Path
lib/exit/timeout.js
20 lines · 767 bytes · JavaScript
Last changed by
Split files (#837)ehmickybefore adoption672c2d7
History of this fileTake it
Split files (#837)ehmickybefore adoption672c2d7
lines 1–20why, one step back1import {setTimeout} from 'node:timers/promises';2import {DiscardedError} from '../return/error.js';34export 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 handling11export const throwOnTimeout = (spawned, timeout, context, controller) => timeout === 0 || timeout === undefined12 ? []13 : [killAfterTimeout(spawned, timeout, context, controller)];1415const killAfterTimeout = async (spawned, timeout, context, {signal}) => {16 await setTimeout(timeout, undefined, {signal});17 context.timedOut = true;18 spawned.kill();19 throw new DiscardedError();20};