An asynchronous event emitter for node.js and the browser. Heavily inspired by component/emitter.
component install matthewmueller/aemitter
npm install aemitter
var Emitter = require'aemitter';var user = name: 'matt' ;Emitteruser;useron'save'// save datanext;useremit'save' data// called after all `save` callbacks have completed;
fn. The signature of
fn will be all the arguments emitted + the
next(err) function. If this function is not specified,
Emitter#on will immediately return.
useron'save'// asynchronous, will wait for `next` to be called;useron'save'// immediately returnsuseremit'save';
It's important to note that
next will be passed as the last argument. If
Emitter#emit passes four arguments,
next will be it's fifth.
Register a single-shot
removed immediately after it is invoked the
fn, or pass only the
name to remove all handlers for
event with variable option args, and a final, optional callback
fn will be called when all the event callbacks have finished.
Caveat: You will need to be consistent with the
emit signature, otherwise
Emitter#on() callbacks will be inconsistent and likely fail. For example:
useremit'save' data message fn; // main signatureuseremit'save' data fn; // will NOT work as expecteduseremit'save' data '' fn; // will work as expecteduseremit'save' data ''; // will also work as expected
Return an array of callbacks, or an empty array.
Check if this emitter has
npm install . mocha test