Registry / devops / async-worker-queue

async-worker-queue

JSON →
library0.2.2jsnpmunverified

A lightweight TypeScript library (v0.2.2, beta) for managing a queue of asynchronous tasks executed with a fixed concurrency using worker threads (or any async function). It exposes a single class AsyncWorkerQueue that supports customizable worker creation, error handling (remove/recreate workers on error), and optional pre-initialization. Unlike generic promise pools, it is tailored for worker-based parallelism with advanced error recovery. Ships TypeScript definitions.

npm install async-worker-queue
INSTALL
IMPORT
SIG · ASYNC-WORKER-QUEUE
A
async-worker-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.

AsyncWorkerQueue
import { AsyncWorkerQueue } from 'async-worker-queue'
const AsyncWorkerQueue = require('async-worker-queue')
Package is ESM and ships TypeScript types. Named export only; no default export.
Execute (type)
import type { Execute } from 'async-worker-queue'
import { Execute } from 'async-worker-queue'
Execute is a type defined as (payload: T) => Promise<R>. Use type import to avoid runtime errors.
AsyncWorkerQueueOptions (type)
import type { AsyncWorkerQueueOptions } from 'async-worker-queue'
Type for options object; exported but not used in the example. Use type import.

Shows instantiation with 3 concurrent workers, explicit initialization, and enqueuing multiple tasks.

import { AsyncWorkerQueue } from 'async-worker-queue'; const createWorker = (i: number) => async (payload: string) => { // Simulate async work await new Promise(resolve => setTimeout(resolve, 100)); return `Worker ${i}: processed ${payload}`; }; async function main() { const queue = new AsyncWorkerQueue(createWorker, 3); await queue.initialise(); const results = await Promise.all([ queue.enqueue('task1'), queue.enqueue('task2'), queue.enqueue('task3') ]); console.log(results); } main().catch(console.error);
Debug
Known issues
gotchaThe `execute` type exported as `Execute` may be misunderstood; it's a generic function type `(payload: T) => Promise<R>`. Ensure proper type parameters.
fix
Use `import type { Execute } from 'async-worker-queue'` and provide T and R when using it as a type.
affects: >=0.0.0
breakingVersion 0.x: API may change without major version bump. Notably, the `_options` parameter uses underscores for private fields, but they are public in the constructor.
fix
Pin exact version and regularly check changelog for breaking changes.
affects: >=0.0.0 <1.0.0
gotchaIf `initialise()` is not called and the first enqueue triggers worker creation, it may cause a delay. The library does not automatically await worker creation before resolving enqueue.
fix
Always call `await queue.initialise()` before enqueuing tasks if worker creation is expensive.
affects: >=0.0.0
gotchaThe `concurrency` parameter sets the number of workers created and the max concurrent tasks. If workers are async but not CPU-bound, you may create more workers than effective parallelism.
fix
Match concurrency to the number of available CPU cores or the bottleneck resource limit.
affects: >=0.0.0
gotchaOptions `removeWorkerOnError` and `recreateWorkerOnError` default to false, meaning failed workers will not be replaced, potentially reducing capacity.
fix
Set `recreateWorkerOnError: true` to automatically restart failed workers.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: worker_queue_1.AsyncWorkerQueue is not a constructor
Using default import instead of named import.
fix
Replace `import AsyncWorkerQueue from 'async-worker-queue'` with `import { AsyncWorkerQueue } from 'async-worker-queue'`.
Property 'initialise' does not exist on type 'AsyncWorkerQueue<unknown, unknown>'
TypeScript version or strict mode; initialise is defined but may be treated as private due to leading underscore in constructor parameters?
fix
Ensure TypeScript strictness settings allow accessing public methods. The library is typed correctly; check for conflicting types.
Upgrade
Version history
0.2.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources
async-worker-queue — npm install async-worker-queue · libregistry