Registry / devops / async-limiter

async-limiter

JSON →
library2.0.0jsnpmunverified

A lightweight job queue for limiting concurrent execution of asynchronous functions. Current stable version is 2.0.0, with low release cadence (last major update in 2020). It implements an Array-like API (push, unshift, splice) to add tasks and supports both callback and promise-based functions. Differentiators: minimal overhead, simple concurrency control (default Infinity), and a clear motivation to avoid performance pitfalls (e.g., zlib with infinite concurrency). Unlike heavyweight libraries like p-limit or bottleneck, it prioritizes simplicity and zero additional dependencies.

npm install async-limiter
INSTALL
IMPORT
SIG · ASYNC-LIMITER
A
async-limiter
devopsjavascriptv2.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Limiter
import { Limiter } from 'async-limiter'
const Limiter = require('async-limiter')
Since v2, the package is ESM-only; named export is 'Limiter'. CommonJS require() will not work. Also ensure you import as named, not default.
Limiter (default import)
import Limiter from 'async-limiter'
const Limiter = require('async-limiter').default
If you use a bundler that supports default interop, you can import as default. But the proper named import is preferred.
type LimiterOptions
import type { LimiterOptions } from 'async-limiter'
Type is exported in v2+ for TypeScript users. You can also inline the options: { concurrency?: number }.
Limiter (CommonJS fallback)
const { Limiter } = await import('async-limiter')
const Limiter = require('async-limiter')
If you must use CommonJS, use dynamic import(). The package does not provide a CJS bundle.

Creates a limiter with concurrency 2, pushes two async functions, and logs results when queue finishes.

import { Limiter } from 'async-limiter'; const limiter = new Limiter({ concurrency: 2 }); const results: string[] = []; function delay(ms: number, value: string): Promise<void> { return new Promise(resolve => setTimeout(() => { results.push(value); resolve(); }, ms)); } limiter.push(async () => { await delay(100, 'two'); }); limiter.push(async () => { await delay(10, 'one'); }); limiter.onDone(() => { console.log('Results:', results); // ['two', 'one'] because concurrency 2 runs both immediately });
Debug
Known issues
breakingVersion 2.0.0 switched to ESM-only (type: module) and renamed the export from 'Queue' to 'Limiter'.
fix
Update imports to use named import `import { Limiter } from 'async-limiter'` instead of `const Queue = require('async-limiter')`, and ensure your project is configured for ESM.
affects: >=2.0.0
gotchaJobs pushed to the queue do not start immediately; they begin processing on the next microtask (next tick). Calling onDone() may not capture jobs added after the tick.
fix
Ensure all jobs are pushed synchronously before expecting onDone() to fire. If you need to add jobs dynamically, call onDone() only when all jobs are queued.
affects: *
gotchaIf concurrency is set to Infinity (default), no actual limiting occurs; all tasks run concurrently, which defeats the purpose.
fix
Set a finite concurrency value in the constructor: `new Limiter({ concurrency: 5 })`.
affects: *
deprecatedThe .onDone() method is a simple callback; it does not return a promise or support async/await out of the box.
fix
No fix available from library. Wrap in a Promise if needed: `await new Promise(resolve => limiter.onDone(resolve))`.
affects: *
gotchaCallbacks passed to push/unshift/splice must invoke their `done` parameter exactly once; otherwise the queue will stall.
fix
Ensure `done()` is called (even on error) to advance the queue. For promises, the done is handled internally.
affects: *
Errors
Common errors & fixes
const Limiter = require('async-limiter'); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module not supported.
Version 2.0.0+ is ESM-only; require() is not allowed.
fix
Use dynamic import or switch to ESM: `const { Limiter } = await import('async-limiter')`
TypeError: t.push is not a function
Importing incorrectly (e.g., `import asyncLimiter from 'async-limiter'` instead of named import).
fix
Use `import { Limiter } from 'async-limiter'` or `import Limiter from 'async-limiter'` (if bundler supports default).
Error: done is not a function
In callback-based jobs, the first argument to the job function is `done`, but the user may have defined parameters in wrong order (e.g., `function(err, done)`).
fix
Job signature: `function(done: () => void) { ... done(); }`. The callback does not accept an error argument.
Warning: Maximum call stack size exceeded
Extremely large number of pending jobs or recursive job scheduling exceeding stack.
fix
Reduce concurrency or queue size; avoid adding new jobs recursively from within a job.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
async-limiter — npm install async-limiter · libregistry