Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

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

About

Execute promises sequentially in batches.

Resources

License

Releases

No releases published

Packages

No packages published