promise-all-batch
v0.0.4
Published
Call concurrent promises in batches
Downloads
7
Maintainers
Readme
📖 Table of Contents
🛠️ Installation
NOTE: The package is using esm modules!
Install the package locally.
npm i promise-all-batch
⚡️ Usage
promiseAllBatch(arr, promiseCallback, size, {
afterEachComplete,
sleepBetween,
});
Basic example that every 1 second will execute 2 numbers in concurrent.
import {promiseAllBatch} from 'promise-all-batch';
const results = await promiseAllBatch(
[1, 2, 3, 4, 5, 6],
(index) => new Promise((resolve) => setTimeout(() => resolve(index), 1000)),
2, // Size of the batch
);
console.log(results); // [1, 2, 3, 4, 5, 6]