easy-promise-queue
Easy promise queue. Set a concurrency to execute promises in the queue.
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 = default;
es2015:
;
How to use
Add Promise thunk to run promise one by one:
let pq = concurrency: 1; pq; pq; // syntax sugar:pq;// is equal to:pq;// is equal to:pq;pq;pq; //The added promises will be executed one by one.
How to pause the queue:
...pq;// you can still add promise, however none of them will run. pq;// Promises will resume to run.