Run promise-returning & async functions concurrently with optional limited concurrency
Similar to Promise.all(), but accepts functions instead of promises directly so you can limit the concurrency.
If you're doing the same work in each function, use p-map instead.
See p-series for a serial counterpart.
npm install p-allimport pAll from 'p-all';
import got from 'got';
const actions = [
() => got('https://sindresorhus.com'),
() => got('https://avajs.dev'),
() => checkSomething(),
() => doSomethingElse()
];
console.log(await pAll(actions, {concurrency: 2}));Returns a Promise that is fulfilled when all promises returned from calling the functions in tasks are fulfilled, or rejects if any of the promises reject. The fulfilled value is an Array of the fulfilled values in tasks order.
Type: Iterable<Function>
Iterable with promise-returning/async functions.
Type: object
Type: number (Integer)
Default: Infinity
Minimum: 1
Number of concurrently pending promises.
Type: boolean
Default: true
When set to false, instead of stopping when a promise rejects, it will wait for all the promises to settle and then reject with an AggregateError containing all the errors from the rejected promises.
Type: AbortSignal
You can abort the promises using AbortController.