async-emitter-component
An event emitter that supports serial execution of asynchronous and synchronous event listeners. The call-chain can be interrupted, similar to the DOM's
e.stopPropagation()
.
about
This is a fork of async-eventemitter, with the following differences:
- Using emitter-component instead of EventEmitter
- Supports a variable number of arguments
- No
before
,after
,at
orfirst
methods, as I consider those to be out of scope.
Because it supports regular (synchronous) listeners, it's a drop-in replacement for emitter-component
.
example
var AsyncEventEmitter = ;var emitter = ; emitter emitter;
usage
Usage is nearly similar to emitter-component and EventEmitter.
on || once(event, [data, ..], [next])
Subscribe to event
. Asynchronous listeners should match the number of event arguments (2 in the example above).
emit(event, [data, ..], [done])
Executes all listeners for the event in order with the supplied data argument(s). The optional callback is called when all of the listeners are done, or if one of them returned an error.
emitSync(event, [data, ..])
Emit synchronously, like the regular Emitter.prototype.emit
.
license
MIT © Andreas Hultgren, Vincent Weevers