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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@alwatr/delay

v6.0.16

Published

Comprehensive toolkit for managing asynchronous operations.

Readme

@alwatr/delay

A robust and lightweight utility library for managing asynchronous operations in JavaScript and TypeScript. @alwatr/delay provides a collection of promise-based functions to pause execution until specific conditions are met, such as timeouts, animation frames, idle callbacks, or DOM events. This helps create clean, readable, and predictable asynchronous code.

Installation

# Using npm
npm install @alwatr/delay

# Using yarn
yarn add @alwatr/delay

Usage

All functions are available under the delay object and return a Promise. You can use them with async/await for clean and linear code flow.

import {delay} from '@alwatr/delay';

async function main() {
  console.log('Waiting for 1 second...');
  await delay.by('1s');
  console.log('Done.');
}

API Reference

  • delay.by(duration: Duration): Promise<void>

    Pauses execution for a specified duration. The duration can be a number (in milliseconds) or a string (e.g., '2s', '500ms').

    await delay.by(2000); // Waits for 2 seconds
    await delay.by('5m'); // Waits for 5 minutes
  • delay.animationFrame(): Promise<DOMHighResTimeStamp>

    Resolves at the beginning of the next browser animation frame. Useful for synchronizing animations and DOM updates with the browser's rendering cycle to avoid layout thrashing.

    const timestamp = await delay.animationFrame();
    console.log(`Rendering next frame at ${timestamp}`);
    // Perform DOM updates here
  • delay.idleCallback(options?: IdleRequestOptions): Promise<IdleDeadline>

    Resolves when the browser's event loop is idle. Ideal for deferring non-critical background tasks to avoid impacting user experience.

    const deadline = await delay.idleCallback({timeout: 1000});
    if (!deadline.didTimeout) {
      console.log('Running background task during idle time.');
    }
  • delay.domEvent<T extends keyof HTMLElementEventMap>(element: HTMLElement, eventName: T, options?: AddEventListenerOptions): Promise<HTMLElementEventMap[T]>

    Waits for a specific DOM event to be dispatched on an HTMLElement.

    const button = document.getElementById('my-button');
    if (button) {
      const event = await delay.domEvent(button, 'click');
      console.log('Button was clicked!', event);
    }
  • delay.event(target: EventTarget, eventName: string, options?: AddEventListenerOptions): Promise<Event>

    A more generic version of domEvent. Waits for any event on any EventTarget (e.g., window, document, or custom event emitters).

    console.log('Waiting for window resize...');
    await delay.event(window, 'resize');
    console.log('Window was resized!');
  • delay.nextMacrotask(): Promise<void>

    Schedules a macrotask to run in the next cycle of the event loop. This is useful for yielding control back to the browser, allowing it to handle rendering and other user-facing tasks. Implemented with setTimeout(..., 0).

    console.log('A');
    await delay.nextMacrotask();
    console.log('B'); // This will log after 'A' and after the browser has had a chance to breathe.
  • delay.nextMicrotask(): Promise<void>

    Queues a microtask to be executed immediately after the current task completes, before the event loop proceeds to the next macrotask. Useful for scheduling work that needs to happen synchronously after an operation but without blocking the main thread.

    console.log('A');
    Promise.resolve().then(() => console.log('C'));
    await delay.nextMicrotask();
    console.log('B'); // Logs A, C, B

Contributing

Contributions are welcome! Please feel free to open an issue or submit a pull request. Read our contribution guidelines to get started.

Sponsors

The following companies, organizations, and individuals support Nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.