Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/seymar/promisebatch
- Owner: seymar
- Created: 2018-05-23T10:30:53.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-05-23T10:52:49.000Z (over 6 years ago)
- Last Synced: 2024-12-31T15:06:34.726Z (29 days ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 completedExample:
```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
```