Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@balena/promise-queue

Package Overview
Dependencies
Maintainers
3
Versions
35
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

  • 1.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
848
increased by62.45%
Maintainers
3
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 19 Oct 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc