Promise-Barrier
This barrier returns a Promise and can operate as a pool.
Interface
const Barrier = require('promise-barrier')
, myData = [ '/home/egroat', '/etc/', '/srv' ]
, poolSize = 2
function myTask(datum) {
return new Promise((pass, fail) => {
// Some async task here, e.g
fs.readdir(datum, 'utf8', (err, files) => {
err ? fail(err) : pass(files)
})
})
}
// Pool size is optional. Unspecified it is infinite
Barrier(myTask, myData, poolSize)
.then((results) => {
// Nothing went wrong
console.log("Correct:", results)
})
.catch((data) => {
// Some failed
console.log("Correct:", data.results)
console.error("Failures:", data.errors)
})