Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

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.

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.