🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

@balena/promise-queue

Package Overview
Dependencies
Maintainers
2
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@balena/promise-queue

Queue sync or async functions with max concurrency, max size, max age, and fifo/lifo ordering

latest
Source
npmnpm
Version
1.3.3
Version published
Weekly downloads
557
-50.97%
Maintainers
2
Weekly downloads
 
Created
Source

promise-queue

This module allows you to queue sync/async functions with max concurrency, max size, max-age, and fifo/lifo ordering

Constructor

let q = new PromiseQueue({
  name: 'device_logs',
  concurrency: 40,
  maxSize: 400,
  maxAge: 30 * 1000,
  order: 'fifo'
});

Use

export function middleware(
	req: Request,
	res: Response,
	next: NextFunction,
): void {
	q.add(() =>
          new Promise(resolve => {
              res.once('close', resolve);
              res.once('finish', resolve);
              next();
          }),
      )
      .catch(err => {
          if (err instanceof PromiseQueueError) {
              reject(res);
          }
      });
}

Metrics

PromiseQueue.metrics is an EventEmitter which emits the following events:

  • arrival, data: undefined: a promise arrives at the queue

  • queueLength, data: number: the length of the queue on arrival

  • inFlight, data: number: the number of active promises on arrival

  • dequeue, data: undefined: a promise stops waiting in the queue and starts processing

  • queueTime, data: number: time a promise spent waiting in queue on dequeue

  • completion, data: undefined: a promise completes processing

  • serviceTime, data: number: time a promise spent processing on completion

  • latency, data: number: sum of queueTime and serviceTime on completion

  • rejection, data: undefined: a promise to be added is rejected because maxSize is already reached

  • timeout, data: undefined: a promise's latency (queue time + service time) exceeds maxAge, and it is rejected

FAQs

Package last updated on 09 Oct 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts