Socket
Socket
Sign inDemoInstall

@balena/promise-queue

Package Overview
Dependencies
2
Maintainers
3
Versions
35
Alerts
File Explorer

Advanced tools

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


Version published
Weekly downloads
875
increased by8.02%
Maintainers
3
Install size
95.5 kB
Created
Weekly downloads
 

Changelog

Source

v1.3.2

(2021-10-19)

  • Fix checking for timed out items [Pagan Gazzard]

Readme

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

Last updated on 19 Oct 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc