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

async-utils-sdk

v1.0.1

Published

A TypeScript-based set of asynchronous utility functions.

Downloads

6

Readme

Async Utils SDK

A TypeScript-based collection of utility functions for asynchronous programming, including features like debouncing, retrying, and caching of promises. Designed to simplify and optimize asynchronous code in JavaScript and TypeScript applications.

Installation

Using npm:

npm install async-utils-sdk

Using yarn:

yarn add async-utils-sdk

After installation, you can import and use the utilities in your project.

Features

  • Debounce: Delay execution of a function until after the specified time has passed since the last invocation.
  • Throttle: Limit the rate at which a function is executed, ensuring it is only called once within a specified time period.
  • Retry: Retry a function (e.g., API request) a specified number of times if it fails.
  • Memoize: Cache the result of an asynchronous function to avoid redundant calculations.
  • Async Map: Map an asynchronous function over an array of items.
  • Async ForEach: Iterate over an array asynchronously, running a function for each item in the array.

Usage

1. Debounce

The debounce function delays the execution of a function until after the specified time has passed since the last invocation.

import { debounce } from 'async-utils-sdk';

const fetchData = async () => {
  console.log('Fetching data...');
};

const debouncedFetch = debounce(fetchData, 2000);

// This will only log 'Fetching data...' once after 2 seconds, no matter how many times it's called
debouncedFetch();
debouncedFetch();
debouncedFetch();

Parameters:

  • fn: The async function to debounce.
  • wait: The time to wait in milliseconds after the last invocation before calling fn.

Returns:

  • A debounced version of the fn function.

2. Throttle

The throttle function limits how often a function can be invoked to once every specified period.

import { throttle } from 'async-utils-sdk';

const logData = async () => {
  console.log('Logging data...');
};

const throttledLog = throttle(logData, 1000);

// This will log 'Logging data...' only once per second, even if it's called multiple times
throttledLog();
throttledLog();
throttledLog();

Parameters:

  • fn: The async function to throttle.
  • wait: The time to wait between invocations.

Returns:

  • A throttled version of the fn function.

3. Retry

The retry function allows you to retry a function multiple times if it fails.

import { retry } from 'async-utils-sdk';

const fetchData = async () => {
  console.log('Trying to fetch data...');
  // Simulate an API call that might fail
  if (Math.random() < 0.5) {
    throw new Error('Failed');
  }
  return 'Data fetched';
};

const retryFetch = retry(fetchData, 3, 1000);

retryFetch().then(console.log).catch(console.error);

Parameters:

  • fn: The async function to retry.
  • retries: The number of retry attempts.
  • delay: The time to wait between retries in milliseconds.

Returns:

  • The result of fn if successful, or an error if all retries fail.

4. Memoize

The memoize function caches the result of a function, preventing it from being called again with the same arguments.

import { memoize } from 'async-utils-sdk';

const calculate = async (x: number) => {
  console.log('Calculating...');
  return x * 2;
};

const memoizedCalculate = memoize(calculate);

memoizedCalculate(5).then(console.log); // Logs: 'Calculating...', 10
memoizedCalculate(5).then(console.log); // Logs: 10 (no calculation)

Parameters:

  • fn: The async function to memoize.

Returns:

  • A memoized version of the fn function.

5. Async Map

The asyncMap function maps an asynchronous function over an array.

import { asyncMap } from 'async-utils-sdk';

const double = async (x: number) => x * 2;

asyncMap([1, 2, 3], double).then(console.log); // Logs: [2, 4, 6]

Parameters:

  • array: The array to iterate over.
  • fn: The async function to apply to each element.

Returns:

  • A promise that resolves to an array of results.

6. Async ForEach

The asyncForEach function iterates over an array asynchronously.

import { asyncForEach } from 'async-utils-sdk';

const logItem = async (item: number) => console.log(item);

asyncForEach([1, 2, 3], logItem); // Logs: 1, 2, 3

Parameters:

  • array: The array to iterate over.
  • fn: The async function to apply to each element.

How to Contribute

Contributions are always welcome! If you'd like to contribute, please follow the steps below:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/your-feature).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add feature').
  5. Push to your branch (git push origin feature/your-feature).
  6. Open a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

Versioning

We use SemVer for versioning. For the available versions, see the tags on this repository.