Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/justforuse/promise-limit-all

Promise all, but with max limit
https://github.com/justforuse/promise-limit-all

javascript promise promise-all

Last synced: about 2 months ago
JSON representation

Promise all, but with max limit

Awesome Lists containing this project

README

        

# Promise Limit All

[![npm](https://img.shields.io/npm/v/promise-limit-all.svg) ![npm](https://img.shields.io/npm/dm/promise-limit-all.svg)](https://www.npmjs.com/package/promise-limit-all)

This package let you control the number of async function at the same time

[Codesandbox](https://codesandbox.io/s/promise-limit-all-demo-v80u1)

## Demo

```js
const promiseLimitAll = require('promise-limit-all');

const promiseFactory = (res, timeout) => {
return () =>
new Promise((resolve) => {
setTimeout(() => {
resolve(res);
}, timeout);
});
};

promiseLimitAll(
[
promiseFactory(1, 1000),
promiseFactory(2, 2000),
promiseFactory(3, 2000),
promiseFactory(4, 1000),
promiseFactory(5, 1000),
promiseFactory(6, 500),
promiseFactory(7, 500)
],
3
).then((res) => {
const str = res.join(",");
console.log(str);
});
```

Output:
```
1,2,3,4,5,6,7
```