Create an AbortSignal that aborts after a timeout, with reset and clear
npm install abort-timerimport abortTimer from 'abort-timer';
const {signal, clear} = abortTimer(5000);
const response = await fetch('https://example.com', {signal});
clear();import abortTimer from 'abort-timer';
const {signal, reset} = abortTimer(5000);
// Extend the deadline by another 5 seconds
reset();
// Or set a new duration
reset(10_000);import abortTimer from 'abort-timer';
{
using timer = abortTimer(5000);
await fetch('https://example.com', {signal: timer.signal});
}
// Timer is automatically cleared when leaving the blockReturns an object with signal, reset, clear, and Symbol.dispose.
Type: number
The timeout duration in milliseconds. Must be a positive finite number.
Type: AbortSignal
The abort signal. Pass this to any API that accepts an AbortSignal.
Reset the timer. Optionally provide a new duration in milliseconds. Defaults to the original duration.
Clear the timer without aborting the signal.
The error class used when the signal is aborted due to timeout. Has name set to 'TimeoutError'.
- is-runtime - Detect the current JavaScript runtime environment
MIT