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

a-promise-queue

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-promise-queue

A native es6 promise queue with optional retry attempts.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

a promise queue

Build Status Coverage Status

This is just another promise queue. Simple.

  • Native es6
  • With concurrency
  • Optional retry attempts for failed promises
  • Option to use your favourite promise flavour (Bluebird, Q)

Install

You know this:

npm install a-promise-queue --save

Interface

  • queue = new PromiseQueue([options], [Function callback]) Callback is fired whenever queue is emptied. If callback is not provided, queue will act as a promise which is resolved once queue is finished. Options:

    {
      promise: Promise, // the type of promises used. defaults to es6 native promises,
      concurrency: Number // set the number of promises to run in parallel.
    }
    
  • queue.length Returns number of promises waiting to be executed.

  • var promise = queue.add(Function generator, [Object options]) Returns a promise which is resolved or rejected when the promise produced by the generator is eventually resolved. Example options:

      {
        attempts: number, // if promise fails it will retry this many times.
        priority: number, // execution is ordered by priority default = 0.
      }
    
  • var promise = queue.flush() Runs all promises currently in the queue concurrently. Returns a promise which is resolved when all promises are finished. Any promises added after .flush() will execute after flush is complete.

Example:

var PromiseQueue = require('a-promise-queue');

var delay = (ms) => () => new Promise(resolve => setTimeout(resolve, ms));

var queue = new PromiseQueue(() => console.log('Queue is empty'));
queue.add(delay(100)).then(() => console.log('first this'));
queue.add(() => Promise.reject('then this fails')).catch((e) => console.log('Errored:', e));
queue.add(delay(10)).then(() => console.log('and this succeeds'));
queue.add(delay(10), { priority: 1 }).then(() => console.log('but not before this one jumps the queue.'));

Keywords

FAQs

Package last updated on 23 Jun 2018

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