Timers
timers/promises.setTimeout()
Returns a promise fulfilled with the supplied value after a timer runs. An abort signal rejects the wait instead. This delays continuation without blocking the JavaScript thread; it does not guarantee precise wall-clock timing. Tested on Node.js 22.16.0. Example output (one line per entry): ["ready", "AbortError"].
Formal Syntax & Structure
nodejs syntaxnodejs
setTimeout([delay[, value[, options]]])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| delay | number | Requested milliseconds. |
| value | any | Fulfillment value. |
| options | object | May include signal and ref. |
Return Value
Promise
Fulfills with value or rejects on cancellation.
Working Example
Example Snippetnodejs
import { setTimeout as wait } from 'node:timers/promises';console.log(await wait(1, 'ready'));const c = new AbortController();c.abort();try { await wait(1000, null, { signal: c.signal });}catch (e) { console.log(e.name);}