Socket
Socket
Sign inDemoInstall

queue-promise

Package Overview
Dependencies
0
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    queue-promise

A simple, dependency-free library for concurrent promise-based queues


Version published
Weekly downloads
14K
increased by2.69%
Maintainers
1
Install size
18.7 kB
Created
Weekly downloads
 

Readme

Source

queue-promise

Greenkeeper badge Build Status npm version npm downloads

queue-promise is a small, dependency-free library for promise-based queues. It will resolve enqueued functions concurrently at a given speed. When a task is being resolved or rejected, an event will be emitted.

Installation

$ npm install queue-promise

Usage

import Queue from "queue-promise";

const queue = new Queue({
  concurrent: 1, // resolve 1 task at a time
  interval: 2000 // resolve a new task once in 2000ms
});

queue.on("resolve", data => console.log(data));
queue.on("reject", error => console.error(error));

queue.push(asyncTaskA); // resolved/rejected after 0s
queue.push(asyncTaskB); // resolved/rejected after 2s
queue.push(asyncTaskC); // resolved/rejected after 4s
queue.push(asyncTaskD); // resolved/rejected after 6s
queue.start();

API

new Queue(options)

Create a new Queue instance.

OptionDefaultDescription
concurrent5How many tasks can be handled at the same time
interval500How often should new tasks be handled (in ms)
public .add(task)/.push(task)

Puts a new task on the stack. Throws an error if the provided task is not a valid function.

public .start()

Starts the queue. Queue will use global Promises.

public .started

Whether the queue has been started or not.

public .stop()

Stops the queue.

public .on(event, callback)

Sets a callback for an event. You can set callback for those events: start, stop, tick, resolve, reject, end.

private .next()

Goes to the next request and stops the loop if there is no requests left.

private .remove(key)/.pop(key)/.shift(key)

Removes a task from the queue.

Tests

$ npm test

Keywords

FAQs

Last updated on 31 Mar 2018

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