npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@se-oss/delay

v1.0.0

Published

A lightweight utility to delay a promise for a specified amount of time.

Readme

@se-oss/delay

CI NPM Version MIT License npm bundle size Install Size

A lightweight utility to delay a promise for a specified amount of time. It's a modern alternative to setTimeout inside an async function.


📦 Installation

npm install @se-oss/delay

pnpm

pnpm install @se-oss/delay

yarn

yarn add @se-oss/delay

📖 Usage

Basic Delay

import delay from '@se-oss/delay';

console.log('Waiting...');
await delay(1000);
console.log('Done!');

Delay with a value

The returned promise resolves with a value.

import delay from '@se-oss/delay';

const result = await delay(100, { value: '🦄' });
console.log(result);
//=> '🦄'

Random Delay

Delay for a random amount of time within a specified range.

import { rangeDelay } from '@se-oss/delay';

console.log('Waiting for a random time between 100ms and 200ms...');
await rangeDelay(100, 200);
console.log('Done!');

Clear a Delay

You can clear a delay before it resolves.

import delay, { clearDelay } from '@se-oss/delay';

const delayedPromise = delay(1000, { value: 'done' });

setTimeout(() => {
  clearDelay(delayedPromise);
}, 500);

const result = await delayedPromise;
// The promise resolves immediately with 'done' when cleared.
console.log(result);
//=> 'done'

Abort Signal

Abort a delay using an AbortSignal.

import delay from '@se-oss/delay';

const controller = new AbortController();

setTimeout(() => {
  controller.abort();
}, 500);

try {
  await delay(1000, { signal: controller.signal });
} catch (error) {
  console.log(error.name); // 500 milliseconds later
  //=> 'AbortError'
}

📚 API

delay(milliseconds, options?)

Returns a promise that resolves after the specified milliseconds.

milliseconds

Type: number

The number of milliseconds to delay.

options

Type: object

value

Type: T

A value to resolve in the returned promise.

signal

Type: AbortSignal

An AbortSignal to abort the delay. The returned promise will be rejected with the signal's reason if the signal is aborted.

rangeDelay(minimum, maximum, options?)

Returns a promise that resolves after a random amount of time between minimum and maximum milliseconds.

minimum

Type: number

The minimum number of milliseconds to delay.

maximum

Type: number

The maximum number of milliseconds to delay.

options

Same options as delay.

clearDelay(promise)

Clears a pending delay. The promise will resolve immediately with its configured value.

promise

Type: Promise<unknown>

The promise returned from delay() or rangeDelay().

createDelay(options)

Creates a new delay instance with custom setTimeout and clearTimeout functions.

options

Type: object

setTimeout

Type: (callback: (...args: any[]) => void, milliseconds: number, ...args: any[]) => unknown

A custom setTimeout function.

clearTimeout

Type: (timeoutId: any) => void

A custom clearTimeout function.

🤝 Contributing

Want to contribute? Awesome! To show your support is to star the project, or to raise issues on GitHub

Thanks again for your support, it is much appreciated! 🙏

License

MIT © Shahrad Elahi and contributors.