promises-in-batches
Execute promises sequentially in batches.
You can executes promises concurrently with a limitation of concurrency.
e.g.) Batch Size: 3
Installation
yarn add promises-in-batches
or
npm install --save-dev promises-in-batches
Usage
import { makePromiseBatch } from "promises-in-batches";
const promiseGenerator1: () => Promise<number> = () =>
new Promise((resolve, _) => {
setTimeout(() => {
resolve(1);
}, 100);
});
const promiseGenerator2: () => Promise<number> = () =>
new Promise((resolve, _) => {
setTimeout(() => {
resolve(2);
}, 300);
});
const promiseGenerator3: () => Promise<number> = () =>
new Promise((resolve, _) => {
setTimeout(() => {
resolve(3);
}, 200);
});
const batchSize = 2;
const results = await makePromiseBatch(
[promiseGenerator1, promiseGenerator2, promiseGenerator3],
batchSize
);
console.log(results);