Skip to content
Execute promises sequentially in batches.
Branch: master
Clone or download
Latest commit 3248603 Feb 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Setup Prettier and CI Feb 12, 2019
src
.gitignore Initial Commit 🐣 Feb 10, 2019
.prettierrc.yaml Setup Prettier and CI Feb 12, 2019
LICENSE.md Add README and LICENSE Feb 12, 2019
README.md
jest.config.js Setup jest Feb 10, 2019
package.json
tsconfig.json Setup jest Feb 10, 2019
yarn.lock

README.md

CircleCI

promises-in-batches

Execute promises sequentially in batches.

You can executes promises concurrently with a limitation of concurrency.

e.g.) Batch Size: 3

promises-in-batches

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); // [ [ 1, 2 ], [ 3 ] ]
You can’t perform that action at this time.