promise-barrier

2.1.0 • Public • Published

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)
    })

Readme

Keywords

none

Package Sidebar

Install

npm i promise-barrier

Weekly Downloads

0

Version

2.1.0

License

UNLICENSED

Last publish

Collaborators

  • gaussflayer