p-limit
Run multiple promise-returning functions with limited concurrency — control how many async operations run in parallel.
p-limit
General JSRun multiple promise-returning functions with limited concurrency — control how many async operations run in parallel.
Fit
Bundle (gzip)
887 B
1.7 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Running Promise.all() on hundreds of async tasks (API calls, file reads, database queries) fires all of them simultaneously, overwhelming the target service or exhausting file descriptor limits.
What It Does
pLimit(n) returns a function that wraps your async operations. It runs at most n at a time, queuing the rest until a slot opens. This prevents overwhelming servers, databases, or the OS while still running multiple operations concurrently.
Installation
npm install p-limitUsage Example
import pLimit from 'p-limit';
const limit = pLimit(5); // max 5 concurrent requests
const urls = Array.from({ length: 100 }, (_, i) => `https://api.example.com/item/${i}`);
const results = await Promise.all(
urls.map((url) =>
limit(async () => {
const res = await fetch(url);
return res.json();
})
)
);
// Fetches 5 URLs at a time, queuing the restRelated packages
Unified TypeScript SDK for building AI-powered apps — switch between 20+ LLM providers without rewriting code.
animejsGeneral JSLightweight JavaScript animation library with a tiny footprint and a powerful, expressive API.
AOSGeneral JSAn easy-to-use library that makes elements fade, slide, or zoom into view as the user scrolls down your page.
archiverGeneral JSStreaming interface for generating ZIP and TAR archives in Node.js — create compressed archives programmatically from files, directories, and buffers.
@formkit/auto-animateGeneral JS> Add smooth transitions to any element with a single line — zero-config animations for adds, removes, and moves.