promise-queues
v1.0.2
Published
A light-weight implementation of asynchronous worker queues using JS promises.
Downloads
2
Maintainers
Readme
Promise Queues
A light-weight implementation of asynchronous worker queues using JS promises.
Install
npm install promise-queues
Usage
const promiseQueue = require('promise-queues');
function myPromise(i) {
return new Promise((resolve, reject) =>
setTimeout(() => resolve('done ' + i), 200)
);
}
// Define the work as an array of functions that create promises.
const work = [() => myPromise(1), () => myPromise(2), () => myPromise(3)];
// Start processing the promise queue using 2 workers.
promiseQueue(work, 2)
.then(result => console.log(result))
.catch(err => console.log(error));
Result:
["done 1", "done 2", "done 3"]