Skip to content

[Replacement]: delay and sleep-promise #1285

Open

Description

@maksimgm

Package to replace

delay, sleep-promise

Package link

https://npmx.dev/package/delay
https://npmx.dev/package/sleep-promise

Native replacement(s)

setTimeout from node:timers/promises

Documentation

https://nodejs.org/api/timers.html#timerspromisessettimeoutdelay-value-options

Availability

Node.js v15+ (v16 stable), Deno and Bun via node:timers/promises

Rationale

both packages wrap setTimeout in a promise, which node has built in. delay is ~7.8M weekly downloads and sleep-promise ~1.1M.

checked delay@7 and sleep-promise@9: await delay(ms, {value}) and setTimeout(ms, value) resolve with the same value, and both reject with AbortError when passed an aborted signal. sleep-promise also has a pass-through form (.then(sleep(ms))), which becomes .then((v) => setTimeout(ms, v)). delay's rangeDelay and clearDelay don't have a native equivalent.

Code example (optional)

import delay from 'delay' // [!code --]
import { setTimeout as delay } from 'node:timers/promises' // [!code ++]

await delay(1000)

Activity

  1. 43081j commented on Nov 24, 2026

    @43081j
    Contributor

    i wonder if this should be a micro utility replacement so we can mention browser support too (setTimeout in a promise).

    thoughts? the example could use node:timers but the message could mention both

  2. maksimgm commented on Nov 24, 2026

    @maksimgm
    ContributorAuthor

    makes sense, i'll do it as a micro-util with the node:timers/promises example and mention new Promise((resolve) => setTimeout(resolve, ms)) for browsers in the description

  3. added
    accepted
    on Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions