N00b's Programming Machine
Unleash awesomeness. Private packages, team management tools, and powerful integrations. Get started with npm Orgs »

multicb

1.2.2 • Public • Published

MultiCB

Simple way to aggregate multiple node-style callbacks

var multicb = require('multicb')
 
// default usage
 
var done = multicb()
doAsync(done())
doAsync(done())
doAsync(done())
done(function(err, results) {
  console.log(err) // => undefined
  console.log(results) /* =>
  [
    [undefined, 'foo'],
    [undefined, 'bar'],
    [undefined, 'baz']
  ]
  */
})
 
// pluck argument
 
var done = multicb({ pluck: 1 })
doAsync(done())
doAsync(done())
doAsync(done())
done(function(err, results) {
  console.log(err) // => undefined
  console.log(results) /* =>
  [
    'foo',
    'bar',
    'baz'
  ]
  */
})
 
// spread argument
 
var done = multicb({ pluck: 1, spread: true })
doAsync(done())
doAsync(done())
doAsync(done())
done(function(err, a, b, c) {
  console.log(err) // => undefined
  console.log(a) // => 'foo'
  console.log(b) // => 'bar'
  console.log(c) // => 'baz'
})

Keywords

none

install

npm i multicb

Downloadsweekly downloads

509

version

1.2.2

license

none

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability