@seymar/promisebatch

1.0.3 • Public • Published

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:

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

Package Sidebar

Install

npm i @seymar/promisebatch

Weekly Downloads

2

Version

1.0.3

License

ISC

Unpacked Size

2.08 kB

Total Files

4

Last publish

Collaborators

  • seymar