Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dawaltconley/parallel-promises
A function for executing a set number of promises in parallel.
https://github.com/dawaltconley/parallel-promises
Last synced: 3 days ago
JSON representation
A function for executing a set number of promises in parallel.
- Host: GitHub
- URL: https://github.com/dawaltconley/parallel-promises
- Owner: dawaltconley
- Created: 2020-06-13T00:00:06.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-07T22:26:29.000Z (about 2 years ago)
- Last Synced: 2024-11-05T16:52:52.629Z (10 days ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# maxAsync
A very simple function for executing async tasks in parallel, with a maximum number of simultaneous tasks.
## Usage
The function takes an array of async functions as its first argument. It's second argument is the maximum number of these functions that should be executed in parallel.
```javascript
const maxAsync = require('@dawaltconley/max-async');const tasks = [
async function () { /* do some async stuff */ },
async function () { /* do some more async stuff */ },
// etc...
];maxAsync(tasks, 4) // execute all tasks, maximum 4 at a time
.then(results => {
// do something with the results;
});
```The function returns a flat array of all async task results, similar to `Promise.all`. The index of each result matches the index of its function in the input array.