Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/morishin/promises-in-batches
Execute promises sequentially in batches.
https://github.com/morishin/promises-in-batches
Last synced: 23 days ago
JSON representation
Execute promises sequentially in batches.
- Host: GitHub
- URL: https://github.com/morishin/promises-in-batches
- Owner: morishin
- License: mit
- Created: 2019-02-12T17:44:43.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2024-03-31T13:47:42.000Z (8 months ago)
- Last Synced: 2024-10-04T10:46:12.064Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/promises-in-batches
- Size: 46.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![CircleCI](https://circleci.com/gh/morishin/promises-in-batches.svg?style=svg)](https://circleci.com/gh/morishin/promises-in-batches)
# 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](https://user-images.githubusercontent.com/1413408/52653624-a7689f80-2f33-11e9-91cf-4064f9a3974b.png)
## Installation
```shell
npm install promises-in-batches
```## Usage
```typescript
import { makePromiseBatch } from "promises-in-batches";const promiseGenerator1: () => Promise = () =>
new Promise((resolve, _) => {
setTimeout(() => {
resolve(1);
}, 100);
});const promiseGenerator2: () => Promise = () =>
new Promise((resolve, _) => {
setTimeout(() => {
resolve(2);
}, 300);
});const promiseGenerator3: () => Promise = () =>
new Promise((resolve, _) => {
setTimeout(() => {
resolve(3);
}, 200);
});const batchSize = 2;
const results = await makePromiseBatch(
[promiseGenerator1, promiseGenerator2, promiseGenerator3],
batchSize
);console.log(results); // [ [ 1, 2 ], [ 3 ] ]
```