promises-in-batches
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

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 ] ]

Readme

Keywords

none

Package Sidebar

Install

npm i promises-in-batches

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

6.76 kB

Total Files

10

Last publish

Collaborators

  • morishin