Globals
AbortSignal.timeout()
Creates a signal that aborts after a delay. Supply it to operations that honor signals; creating a signal alone cannot stop arbitrary synchronous JavaScript. The test uses an independent referenced timer only to keep the process alive. Tested on Node.js 22.16.0. Example output (one line per entry): ["TimeoutError"].
Formal Syntax & Structure
nodejs syntaxnodejs
AbortSignal.timeout(delay)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| delay | number | Requested milliseconds. |
Return Value
AbortSignal
Signal that later aborts.
Working Example
Example Snippetnodejs
import { setTimeout as wait } from 'node:timers/promises';const signal = AbortSignal.timeout(1);const done = new Promise(r => signal.addEventListener('abort', r, { once: true }));await Promise.all([done, wait(5)]);console.log(signal.reason.name);