All Projects → chenzhihao → easy-promise-queue

chenzhihao / easy-promise-queue

Licence: MIT license
An easy JavaScript Promise queue which is automatically executed, concurrency controlled and suspendable.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to easy-promise-queue

Wx Promise Request
解决微信小程序 wx.request 请求的并发数限制、不支持异步问题
Stars: ✭ 226 (+629.03%)
Mutual labels:  queue, promise
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+522.58%)
Mutual labels:  promise, concurrency
Task Easy
A simple, customizable, and lightweight priority queue for promises.
Stars: ✭ 244 (+687.1%)
Mutual labels:  queue, promise
Unagi Chan
A haskell library implementing fast and scalable concurrent queues for x86, with a Chan-like API
Stars: ✭ 115 (+270.97%)
Mutual labels:  queue, concurrency
best-queue
Queue in runtime based promise
Stars: ✭ 26 (-16.13%)
Mutual labels:  queue, promise
Goconcurrentqueue
Go concurrent-safe, goroutine-safe, thread-safe queue
Stars: ✭ 127 (+309.68%)
Mutual labels:  queue, concurrency
linked-blocking-multi-queue
A concurrent collection that extends the existing Java concurrent collection library, offering an optionally-bounded blocking "multi-queue" based on linked nodes.
Stars: ✭ 41 (+32.26%)
Mutual labels:  queue, concurrency
Mpmcqueue
A bounded multi-producer multi-consumer concurrent queue written in C++11
Stars: ✭ 468 (+1409.68%)
Mutual labels:  queue, concurrency
beems
a bee-queue based minimalist toolkit for building fast, decentralized, scalable and fault tolerant microservices
Stars: ✭ 33 (+6.45%)
Mutual labels:  queue, concurrency
wtsqs
Simplified Node AWS SQS Worker Wrapper
Stars: ✭ 18 (-41.94%)
Mutual labels:  queue, promise
Promise Queue Plus
Promise-based queue. Support timeout, retry and so on.
Stars: ✭ 113 (+264.52%)
Mutual labels:  queue, promise
ProtoPromise
Robust and efficient library for management of asynchronous operations in C#/.Net.
Stars: ✭ 20 (-35.48%)
Mutual labels:  promise, concurrency
P Queue
Promise queue with concurrency control
Stars: ✭ 1,863 (+5909.68%)
Mutual labels:  queue, promise
Promise Queue
Promise-based queue
Stars: ✭ 210 (+577.42%)
Mutual labels:  queue, promise
Arq
Fast job queuing and RPC in python with asyncio and redis.
Stars: ✭ 695 (+2141.94%)
Mutual labels:  queue, concurrency
p-ratelimit
Promise-based utility to make sure you don’t call rate-limited APIs too quickly.
Stars: ✭ 49 (+58.06%)
Mutual labels:  promise, concurrency
queue-promise
A simple, dependency-free library for concurrent promise-based queues. Comes with with concurrency and timeout control.
Stars: ✭ 56 (+80.65%)
Mutual labels:  queue, promise
Spscqueue
A bounded single-producer single-consumer wait-free and lock-free queue written in C++11
Stars: ✭ 307 (+890.32%)
Mutual labels:  queue, concurrency
async
Synchronization and asynchronous computation package for Go
Stars: ✭ 104 (+235.48%)
Mutual labels:  promise, concurrency
conquerant
lightweight async/await for Clojure
Stars: ✭ 31 (+0%)
Mutual labels:  promise, concurrency

easy-promise-queue

Easy promise queue. Set a concurrency to execute promises in the queue.

NPM

Build Status codecov

English 中文

What is it used for

It's a concurrent queue which can pause.

When its concurrency is set as 1(by default), it's a FIFO queue.

You can put Promises into this queue. Only X promises can be executed concurrently as your configuration.

You can pause/resume this queue at any time. When the queue is paused, ongoing promises will keep running until done though.

Installation

$ npm install easy-promise-queue

Usage

How to import

commonJS:

const PromiseQueue = require("easy-promise-queue").default;

es2015:

import PromiseQueue from 'easy-promise-queue';

How to use

Add Promise thunk to run promise one by one:

let pq = new PromiseQueue({concurrency: 1});

pq.add(() => {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      console.log('task 1');
      resolve();
    }, 1000)
  });
});

pq.add(() => {
  return new Promise(function (resolve, reject) {
    setTimeout(function () {
      console.log('task 2');
      resolve();
    }, 1000)
  });
});

// syntax sugar:
pq.add([promiseThunk, promiseThunk, promiseThunk]);
// is equal to:
pq.add(promiseThunk).add(promiseThunk).add(promiseThunk);
// is equal to:
pq.add(promiseThunk);
pq.add(promiseThunk);
pq.add(promiseThunk);

//The added promises will be executed one by one.

How to pause the queue:

...
pq.pause();
// you can still add promise, however none of them will run.

pq.resume();
// Promises will resume to run.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].