Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/seymar/promisebatch

Executes an array of promises in batches.
https://github.com/seymar/promisebatch

Last synced: 18 days ago
JSON representation

Executes an array of promises in batches.

Awesome Lists containing this project

README

        

# promiseBatch

Executes an array of promises in batches.

Arguments:
* **size** The size of each batch
* **promiseFunctions** An array of functions that return promises
* **onBatchCompleteCallback** (optional) A function that gets called when a batch is completed

Example:

```javascript
const promiseBatch = require('./promisebatch.js')

const arr = [3, 2, 1, 6, 5, 4, 9, 8, 7, 10]

promiseBatch(3, arr.map(a => () => new Promise((resolve, reject) => {
setTimeout(() => {
console.log(a)
resolve()
}, a * 100)
})), () => console.log('Batch complete'))
.then(() => {
console.log('All done')
})
```
Result:
```
1
2
3
Batch complete
4
5
6
Batch complete
7
8
9
Batch complete
10
Batch complete
All done
```