Promise.all() with concurrency limit
npm install parallel-promises


![]()

ParallelPromises is an NPM package implemented in Typescript for executing a set of Promises with a given concurrency limit.
This project is inspired by https://itnext.io/node-js-handling-asynchronous-operations-in-parallel-69679dfae3fc
Install it on your project
``Shell`
npm install --save parallel-promises
`typescript
import { customPromiseAll } from 'parallel-promises';
...
const concurrentLimit: number = 5;
const listOfPromises: ICustomPromise[] = [
{
name: 'GetSomething',
function: this.operationWrapper.getSomethingFunction,
thisArg: this.operationWrapper,
args: ["firstParamForFunction",{ data: "Another param"}, ["more params..."]]
},
{
name: 'CreateSomething',
function: this.createSomething,
thisArg: undefined,
args: ["firstParamForFunction"]
},
{
name: 'RefreshSomething',
function: this.updateSomething,
},
...
]
customPromiseAll(listOfPromises, concurrentLimit).then((result: IAnyObject)=>{
console.log(result);
//{ GetSomething: { Response: ... }, CreateSomething: "{ Id: 8 }", RefreshSomething: "OK" , ...}
...
// do whatever you want
});
`
Usage with Javascript
`javascript
const ParallelPromises = require('parallel-promises');
...
const concurrentLimit = 5;
const listOfPromises = [
{
name: 'GetSomething',
function: this.operationWrapper.getSomethingFunction,
thisArg: this.operationWrapper,
args: ["firstParamForFunction",{ data: "Another param"}, ["more params..."]]
},
{
name: 'CreateSomething',
function: this.createSomething,
thisArg: undefined,
args: ["firstParamForFunction"]
},
{
name: 'RefreshSomething',
function: this.updateSomething,
},
...
]
ParallelPromises.customPromiseAll(listOfPromises, concurrentLimit).then((result)=>{
console.log(result);
//{ GetSomething: { Response: ... }, CreateSomething: "{ Id: 8 }", RefreshSomething: "OK" , ...}
...
// do whatever you want
});
``
Rafael Pernil Bronchalo - Developer