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

@litert/utils-async

v1.6.0

Published

The utility functions/classes/constants about asynchronous operations for JavaScript/TypeScript.

Downloads

287

Readme

LiteRT/Utils - Async

Strict TypeScript Checked npm version License node GitHub issues GitHub Releases

The utility functions/classes/constants about asynchronous operations for JavaScript/TypeScript.

Requirement

  • TypeScript v5.0.0 (or newer)
  • Node.js v18.0.0 (or newer)

Installation

npm i @litert/utils-async --save

Usage

API sleep

This API provides a way to pause execution for a specified duration, asynchronously.

import { sleep } from '@litert/utils-async';

await sleep(2000); // Sleep for 2 seconds

API autoRetry

This API provides automatic retry functionality for (asynchronous) operations.

import { autoRetry } from '@litert/utils-async';

const ac = new AbortController(); // Optional, to allow aborting the retry operation
await autoRetry({
    'maxRetries': 5, // Retry no more than 5 times if the first call fails
    'function': async (ctx) => {
        // Your function logic here
    },
    // Optional, `DEFAULT_BEFORE_RETRY` will be used if omitted.
    'beforeRetry': async (ctx) => {
        // Your beforeRetry logic here
    },
    // Optional, an AbortSignal to allow the retry operation to be aborted.
    'signal': ac.signal,
});

API withTimeout

This API binds a timeout to an asynchronous operation, without modifying the original function.

import { withTimeout } from '@litert/utils-async';

await withTimeout(5000, async () => {
    // Your async code here
});

API withAbortSignal

This API binds an AbortSignal to an asynchronous operation, without modifying the original function.

import { withAbortSignal } from '@litert/utils-async';

const ac = new AbortController();

await withAbortSignal(ac.signal, async () => {
    // Your async code here
});

Class AbortTimeoutController

This class is an extension of the standard AbortController that automatically aborts after a specified timeout.

import { AbortTimeoutController } from '@litert/utils-async';

const atc = new AbortTimeoutController(3000); // Automatically abort after 3 seconds

// Use `atc.signal` in your async operations

Class BackgroundRunner

This class allows running asynchronous tasks in the background, managing their lifecycle.

import { BackgroundRunner } from '@litert/utils-async';

const runner = new BackgroundRunner();

runner.on('error', (err) => {
    console.error('Background task error:', err);
});

// Start a background task immediately
runner.run(async () => {
    // Your background task logic here
});

// Run a background task after a delay (default is in the next tick)
runner.runLater(async () => {
    // Your delayed background task logic here
});

Class PromiseController

Unlike the new Promise(...) flow, this class provides control over a Promise, allowing external resolution or rejection.

import { PromiseController } from '@litert/utils-async';

const pc = new PromiseController<number>();

setTimeout(() => {
    pc.resolve(42); // Resolve the promise with the value 42 after 1 second
}, 1000);

pc.promise.then((value) => {
    console.log('Promise resolved with value:', value);
});

Documentation

License

This library is published under Apache-2.0 license.