async-emit

1.0.1 • Public • Published

async-emit

Emits an event on an EventEmitter where the listener may include a callback function

An asyncEmit() function that accepts an EventEmitter, an Array of args, and a callback function. If the emitter listener function has an arity > args.length then there is an assumed callback function on the emitter, which means that it is doing some async work. We have to wait for the callbacks for any async listener functions.

It works like this:

var emitter = new EventEmitter()
 
// this is an async listener
emitter.on('something', function (val, done) {
  // val may be any number of input arguments
  setTimeout(function () {
    done()
  }, 1000)
})
 
// this is a sync listener, no callback function
emitter.on('something', function (val) {
 
})
 
asyncEmit(emitter, 'something', [ 5 ], function (err) {
  if (err) throw err
  console.log('DONE!')
})

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    89
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    89
  • 1.0.0
    0

Package Sidebar

Install

npm i async-emit

Weekly Downloads

89

Version

1.0.1

License

MIT

Last publish

Collaborators

  • tootallnate