An EventEmitter that supports serial execution of asynchronous event listeners. It also supports event listeners without callbacks (synchronous), as well as interrupting the call-chain (similar to the DOM's e.stopPropagation()).
var AsyncEventEmitter = ;var events = ;events;events;events;
More examples are found in the
Important differences between AsyncEventEmitter the native EventEmitter
The API and behavior of AsyncEventEmitter is as far as possible and meaningful identical to that of the native EventEmitter. However there are some important differences which should be noted.
- Data sent to event listeners (
eg emit(data)) must always be zero or one argument, and can not be a function.
- Event listeners will always recieve the data object, which may or may not be undefined.
- The second argument can only be a callback, and will only be supplied if
the event listener has an arity of two or more (eg
- Event listeners with an arity of one or zero (eg without a callback argument specified) will be treated as synchronous.
- Even if all event listeners are synchronous, they will still be executed
asynchronously (through setImmediate) and thus code suceeding
.emit()will be executed before any event listeners.
- Interupt the callback chain in async listeners by calling the callback with the error as the first parameter; in sync listeners by throwing an Error.
addListener() on() once() removeListener() removeAllListeners() setMaxListeners() listeners() see the EventEmitter docs,
nothing new here.
emit(event, [data], [callback])
Executes all listeners for the event in order with the supplied data argument. The optional callback is called when all of the listeners are done.
Adds a listener to the beginning of the listeners array for the specified event.
.at(event, index, listener)
Adds a listener at the specified index in the listeners array for the specified event.
.before(event, target, listener)
Adds a listener before the target listener in the listeners array for the specified event.
.after(event, target, listener)
Adds a listener after the target listener in the listeners array for the specified event.
- Create an issue and tell me what you're gonna do, just to make sure there's no duplicate work
- Fork and branch your feature-branch of the develop branch
- Write tests for changed/added functionality and make sure you don't break existing ones
- Adhere to existing code style
- Submit a pull-request to the develop branch
The MIT License (MIT)
Copyright © 2013 Andreas Hultgren