A simple and fast way to manage concurrent promise tasks with Queue Data Structure.
MIT License
A simple and fast way to manage concurrent promise tasks with Queue Data Structure.
Sometimes you have to do any large concurrent processing using a Promise
list and you don't want to Promise.all
then because it will load all the promises into memory and will stop when any error occur. This package can help you with that! You can run concurrent promise by queuing it and set if it can continue processing even if any error occur. It has zero external dependencies.
npm i concurrent-manager
import ConcurrentManager from 'concurrent-manager';
const concurrent = new ConcurrentManager({
concurrent: 10, // max concurrent process to be run
withMillis: true // add millisecond tracing to process
});
concurrent.queue(() => {
return doSomethingPromiseRequest();
});
// or
concurrent.queue(async() => {
const response = await doSomethingPromiseRequest();
return response;
});
// Run all queued process
console.log(concurrent.getListedProcess());
concurrent.run()
.then(() => {
// You can access that fulfilled & rejected are here
console.log(concurrent.getListedProcess());
});
But, you can run it independently too!
const processId = concurrent.queue(() => {
return doSomethingPromiseRequest();
});
concurrent.getProcess(processId)
.run()
.then((response) => {
console.log('Response ==>', response);
});
You can alse re-trying run promise if that has rejected.
async function main() {
concurrent.queue(() => {
return doSomethingPromiseRequest();
});
// or
concurrent.queue(async() => {
const response = await doSomethingPromiseRequest();
return response;
});
// Run all queued promises
await concurrent.run()
const rejected = concurrent.getProcess('rejected');
concurrent.getListedProcess('rejected')
.forEach((process) => process.run());
}
version
in package.json
is changed to newest version. Then run npm install
for synchronize it to package-lock.json
main
, you can publish the packages by creating new Relase here: https://github.com/gadingnst/concurrent-manager/releases/new
tag
, make sure the tag
name is same as the version
in package.json
.Publish Release
button, then wait the package to be published.concurrent-manager
is freely distributable under the terms of the MIT license.
Feel free to open issues if you found any feedback or issues on concurrent-manager
. And feel free if you want to contribute too! 😄
Built with ❤️ by Sutan Gading Fadhillah Nasution on 2022