2.1.0 • Published 8 years ago

promise-barrier v2.1.0

Weekly downloads
2
License
UNLICENSED
Repository
github
Last release
8 years ago

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

8 years ago

2.0.2

8 years ago

2.0.1

8 years ago

2.0.0

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago