Skip to content

Awaitable timers #7340

Closed
Closed
@jasnell

Description

@jasnell

In Node.js 15.x, we introduced the concept of awaitable timers... variants of setTimeout() and setInterval() that return promises. For instance:

https://nodejs.org/dist/latest-v17.x/docs/api/timers.html#timers-promises-api

import { setTimeout } from 'timers/promises';

// Halts execution for approximately 1 second without blocking the event loop
await setTimeout(1000);

https://nodejs.org/dist/latest-v17.x/docs/api/timers.html#timerspromisessetintervaldelay-value-options

import { setInterval } from 'timers/promises';

// Iterates approximately once per second without blocking the event loop
for await (const _ of setInterval(1000) {
  console.log('.');
}

These have proven to be very useful for a number of cases and I believe it's worthwhile to at least discuss whether they should be standardized in some variation within the HTML spec.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions