Skip to content

node:timers

How Elide supports Node's timers and timers/promises modules: they match Node, including scheduler; active() and unenroll() are not exposed.

On this page

node:timers and node:timers/promises match Node’s timers, including scheduler and AbortSignal support; ordering is covered under Timers.

Example

js
// timers.mjs
import { setInterval, setTimeout as sleep } from "node:timers/promises";

console.log(await sleep(10, "woke"));

let ticks = 0;
for await (const _ of setInterval(5)) {
  if (++ticks === 3) break;
}
console.log("ticks", ticks);

const controller = new AbortController();
const pending = sleep(60_000, null, { signal: controller.signal });
controller.abort();
await pending.catch((error) => console.log(error.name));
utf-8 · js · Lines: 15

elide run timers.mjs prints:

text
woke
ticks 3
AbortError
utf-8 · text · Lines: 3

Differences from Node

  • node:timers functions are not the same objects as the timer globals.
  • active() and unenroll() are not exposed.

Reference

Status: Full · 54 of 57 suite tests pass (94.7%) · since 1.1.0

Exports

ExportKindStatusNotes
setTimeout()functionFullSchedules a callback to be invoked once after delay milliseconds
clearTimeout()functionFullCancels a timeout previously established by setTimeout()
setInterval()functionFullSchedules a callback to be invoked repeatedly every delay milliseconds
clearInterval()functionFullCancels an interval previously established by setInterval()
setImmediate()functionFullSchedules a callback to be invoked asynchronously “immediately” (after I/O events but before timers…
clearImmediate()functionFullCancels an immediate action previously established by setImmediate()

Tests: node-api node:timers: 54 pass, 3 fail, 0 error, 10 skipped. Failing: test-timers-max-duration-warning.js, test-timers-timeout-to-interval.js, test-timers-unenroll-unref-interval.js.

Was this page helpful?