Skip to content

seymar/promisebatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Executes an array of promises in batches.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published