Registry / devops / esm-async-queue

esm-async-queue

JSON →
library0.2.2jsnpmunverified

ESM-only, dependency-free async queue for Node.js and browsers. Version 0.2.2 (released 2024). Processes n tasks concurrently, starting immediately on push. Includes TypeScript definitions and event subscriptions (idle, taskProcessing, taskProcessed, taskPushed). No dependencies. Lightweight alternative to async.queue or p-limit.

npm install esm-async-queue
INSTALL
IMPORT
SIG · ESM-ASYNC-QUEUE
E
esm-async-queue
devopsjavascriptv0.2.2
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.

Queue
import { Queue } from 'esm-async-queue'
const Queue = require('esm-async-queue')
Package is ESM-only; CommonJS require() throws ERR_REQUIRE_ESM.
Queue (default import)
import { Queue } from 'esm-async-queue'
import Queue from 'esm-async-queue'
No default export; named import 'Queue' only.
Queue type
import type { Queue } from 'esm-async-queue'
TypeScript users can import the type for type annotations.

Creates a queue with concurrency 2, pushes three async tasks, and subscribes to the 'idle' event.

import { Queue } from 'esm-async-queue'; const delayed = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); const queue = new Queue({ concurrency: 2 }); queue.push(() => delayed(200).then(() => console.log('task 1 done'))); queue.push(() => delayed(100).then(() => console.log('task 2 done'))); queue.push(() => delayed(300).then(() => console.log('task 3 done'))); queue.subscribe('idle', () => console.log('all tasks complete'));
Debug
Known issues
gotchaQueue length includes all tasks (pending + processing), not just pending.
fix
Use 'tasksProcessing' and 'tasksPending' properties separately to track specific counts.
affects: >=0.0.0
gotchaEvent subscription returns an unsubscribe function, but calling it more than once causes a console.warn.
fix
Unsubscribe only once per subscription; avoid double unsubscribe.
affects: >=0.0.0
gotchaTasks must be functions that return a PromiseLike or be async. Passing a plain Promise directly will not work.
fix
Wrap promises in a function: () => myPromise.
affects: >=0.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() to import an ESM-only module.
fix
Change to import statement: import { Queue } from 'esm-async-queue'
TypeError: queue.push is not a function
Using default import instead of named import.
fix
Use import { Queue } from 'esm-async-queue' (curly braces).
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
esm-async-queue — npm install esm-async-queue · libregistry