Run async functions with limited concurrency. Same API as p-limit, but ships both ESM and CJS with zero dependencies.
import { pLimit } from "tiny-limit";
const limit = pLimit(5);
const results = await Promise.all(urls.map((url) => limit(() => fetch(url))));496 bytes gzipped. Zero dependencies.
Demo built with remotion-readme-kit
npm install tiny-limitimport { pLimit } from "tiny-limit";
const limit = pLimit(3);
const input = [
limit(() => fetchUser(1)),
limit(() => fetchUser(2)),
limit(() => fetchUser(3)),
limit(() => fetchUser(4)),
limit(() => fetchUser(5)),
];
const users = await Promise.all(input);const limit = pLimit(2);
const result = await limit(fetch, "https://example.com");limit.activeCount; // currently running
limit.pendingCount; // waiting in queue
limit.concurrency; // get or set the limit
limit.clearQueue(); // discard pending tasksp-limit v4+ is ESM-only. If you require("p-limit") in a CommonJS project, you get ERR_REQUIRE_ESM. tiny-limit works with both import and require().
p-limit |
tiny-limit |
|
|---|---|---|
| CJS support | v3 only (v4+ ESM-only) | ESM + CJS |
| Dependencies | yocto-queue |
0 |
| TypeScript | native (v6+) | native |
| Export | default | named |
- import pLimit from "p-limit";
+ import { pLimit } from "tiny-limit";One line. The rest of your code stays the same.
Returns a limit function that queues async work up to the given concurrency. Throws if concurrency is not a positive integer (or Infinity).
Queues fn(...args) and returns a promise.
Number of promises currently running.
Number of promises waiting in the queue.
Get or set the concurrency limit at runtime.
Discards all pending tasks.
Drop-in replacements for sindresorhus async utilities. All ship ESM + CJS with zero dependencies.
| Package | Replaces | What it does |
|---|---|---|
| tiny-limit | p-limit | Concurrency limiter |
| tiny-map | p-map | Concurrent map with order |
| tiny-retry | p-retry | Retry with exponential backoff |
| tiny-queue | p-queue | Priority task queue |
| tiny-ms | ms | Parse/format durations |
| tiny-escape | escape-string-regexp | Escape regex chars |
Want all async utilities in one import? Use tiny-pasync.
If this saved you from ERR_REQUIRE_ESM, star the repo or open an issue if something breaks.
