fanin - the fan-in concurrency pattern


A simple concurrency pattern: fan-in

Status: Untested in production, but ready to be.

  • You want to make n asynchronous calls simultaneously and make a callback when all have finished.
  • You may want to save the callback values of these calls, and definitely want the errors.
  • You just want that. Nothing else.
var fanin = require('fanin')
  , fan = fanin(3, cb);


// cb(array_of_errs, {foo: foo_obj, bar: bar_obj}); will be called.
  • var fan = fanin(n, cb) returns a function which will act as a callback to the sub-calls in which you only care about errors.
  • fan.capture(name) will act as a callback to the sub-calls which you care about return value (placing them in an object under the key name.
  • options:
    • joinErrs is an optional argument to join the error list (it can be a string to join on or true for .join('; '))

npm install after

npm test

MIT License found in the LICENSE file.