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

ts-wait

v2.1.1

Published

A TypeScript library for implementing customizable polling mechanisms with adjustable timeouts and intervals.

Readme

Wait Library

The Wait library provides a convenient way to implement polling mechanisms with customizable timeouts and intervals in TypeScript.

Installation

You can install the Wait library via npm:

npm install ts-wait

Usage

import { Wait } from 'ts-wait';

// Basic usage
await new Wait<Document>(() => client.documents.getDocument(id))
        .pollingEvery(1000)
        .withTimeout(20000)
        .until(document => document.status === 'COMPLETED')

// With maximum attempts limit
await new Wait<Document>(() => client.documents.getDocument(id))
        .pollingEvery(1000)
        .withMaxAttempts(10) // Stop after 10 polling attempts
        .until(document => document.status === 'COMPLETED')

// With exponential backoff
await new Wait<Document>(() => client.documents.getDocument(id))
        .pollingEvery(1000) // Initial interval
        .withExponentialBackoff(2, 10000) // Multiply by 2 each time, max 10 seconds
        .withTimeout(60000)
        .until(document => document.status === 'COMPLETED')

// Combining features
await new Wait<Document>(() => client.documents.getDocument(id))
        .pollingEvery(500)
        .withMaxAttempts(15)
        .withExponentialBackoff(1.5) // Gradually increase with 1.5x multiplier
        .withTimeout(30000)
        .until(document => document.status === 'COMPLETED')       

API

Wait<T> A class that represents the Wait library.

Constructor new Wait(call: () => Promise<T>): Creates a new Wait instance with the provided asynchronous function.

Methods:

withTimeout(timeout: number): Wait<T>: Sets the timeout for waiting in milliseconds (default: 30000)

pollingEvery(interval: number): Wait<T>: Sets the polling interval in milliseconds (default: 1000).

withMessage(message: string): Wait<T>: Sets a custom error message.

withMaxAttempts(maxAttempts: number): Wait<T>: Sets the maximum number of polling attempts. The polling will stop when either the timeout is reached or the maximum number of attempts is exceeded, whichever comes first.

withExponentialBackoff(multiplier: number = 2, maxInterval?: number): Wait<T>: Enables exponential backoff for the polling interval. The interval will be multiplied by the specified multiplier after each attempt. Optionally, you can set a maximum interval to cap the growth.

  • multiplier: The factor by which to multiply the interval (default: 2)
  • maxInterval: Optional maximum interval in milliseconds to prevent unbounded growth

async until(condition: (it: T) => boolean): Promise<T>: Waits until the provided condition function returns true or the timeout/max attempts is reached. Returns the result when the condition is met.

Contributions

Contributions are welcome! Feel free to submit issues or pull requests.

License

This library is licensed under the MIT License. See the LICENSE file for details.