%% generate tags start %%
#software-engineering
%% generate tags end %%
#software-engineering/typescript
Following packages might help
## Pure JS
```js
function promiseAllWithConcurrency(promises, concurrency) {
const results = [];
let index = 0;
function executeNext() {
if (index < promises.length) {
const promise = promises[index];
index++;
Promise.resolve(promise())
.then(result => {
results.push(result);
})
.catch(error => {
results.push(error);
})
.then(() => {
executeNext();
});
}
}
const promisesToExecute = [];
for (let i = 0; i < concurrency; i++) {
promisesToExecute.push(executeNext());
}
return Promise.all(promisesToExecute).then(() => results);
}
```
```js
const promises = [
() => fetch("https://example.com/1"),
() => fetch("https://example.com/2"),
() => fetch("https://example.com/3"),
() => fetch("https://example.com/4"),
() => fetch("https://example.com/5")
];
promiseAllWithConcurrency(promises, 2).then(results => {
console.log(results);
});
```
## Async Sema
[vercel/async-sema: Semaphore using `async` and `await` (github.com)](https://github.com/vercel/async-sema)
## Effect
[[Typesafe error|Typescript Effect]]
## Pall
[sindresorhus/p-all: Run promise-returning & async functions concurrently with optional limited concurrency (github.com)](https://github.com/sindresorhus/p-all)
## Pool
[ricokahler/pool: like Promise.all but you can limit the concurrency (github.com)](https://github.com/ricokahler/pool)