Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/justforuse/promise-limit-all
- Owner: justforuse
- Created: 2021-09-11T13:37:53.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-12-31T07:36:00.000Z (about 3 years ago)
- Last Synced: 2024-11-13T23:04:45.534Z (about 2 months ago)
- Topics: javascript, promise, promise-all
- Language: JavaScript
- Homepage: https://codesandbox.io/s/promise-limit-all-demo-v80u1
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
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
```