Registry / devops / blocking-queue

blocking-queue

JSON →
library0.0.1jsnpmunverified

A simple blocking FIFO queue and flow control library using Promises, allowing consumers to process tasks with a configurable concurrency limit. Version 0.0.1 is the initial release. It provides a Queue class for push/pop operations and a QueueConsumer to start/stop task processing. Different from full-featured message queues like Bull or Kue, this is lightweight and designed for in-process task orchestration. The library is minimal but functional, suitable for simple sequential or parallel task execution in Node.js.

npm install blocking-queue
INSTALL
IMPORT
SIG · BLOCKING-QUEUE
B
blocking-queue
devopsjavascriptv0.0.1
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 'blocking-queue'
const Queue = require('blocking-queue').Queue
Default export is the Queue class; named and default exports are identical.
QueueConsumer
import { QueueConsumer } from 'blocking-queue'
const QueueConsumer = require('blocking-queue').QueueConsumer
Named export from the package.
Queue as default
import Queue from 'blocking-queue'
const Queue = require('blocking-queue')
The default export is the Queue class itself.

Creates a queue, pushes tasks, starts a consumer with concurrency 2, and waits for all tasks to complete.

import { Queue, QueueConsumer } from 'blocking-queue'; const q = new Queue(); q.push('task1'); q.push('task2'); q.push('task3'); q.push('task4'); q.push('task5'); const c = new QueueConsumer(q); c.start(async (task) => { console.log('Processing', task); }, 2); (async () => { await c.end(); console.log('All tasks done'); })();
Debug
Known issues
gotchaQueueConsumer's start method's callback must return a Promise. If using async/await in the callback, ensure it returns the promise explicitly or use async function.
fix
Use an async function: start(async (task) => { ... }) or return a Promise.
affects: 0.0.1
gotchaQueue.pop() returns a Promise that resolves when a task is available. If the queue is empty, it will never resolve until a push occurs.
fix
Ensure tasks are pushed before or concurrently with pop calls.
affects: 0.0.1
gotchaQueueConsumer.end() resolves immediately if the queue is empty and no tasks are in progress. If tasks are still processing, it waits for them to finish.
fix
Call end after all pushes and ensure the consumer is started.
affects: 0.0.1
Errors
Common errors & fixes
TypeError: Queue is not a constructor
Incorrect import: using named import when default was expected, or vice versa.
fix
Use 'import Queue from 'blocking-queue'' or 'const Queue = require('blocking-queue')'.
TypeError: consumer is not a function
Passing a non-function to QueueConsumer.start().
fix
Ensure the first argument to start is a function that returns a Promise.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
blocking-queue — npm install blocking-queue · libregistry