emit-then
EventEmitter.prototype.emit
that wraps event calls in a promise.
Installation
$ npm install emit-then
Setup
Add emitThen
to your emitter prototype(s):
httpserveremitThen = ;
Or register emitThen
on EventEmitter.prototype
to make it available on all emitters:
;
Usage
Traditional event handlers behave as usual:
emitter;emitter;
Handlers can return promises:
emitter ;
Just like calling emit
, the return value or resolution of the promise is unused.
If a handler returns a rejected promise, emitThen
is immediately rejected with the error:
emitter ;
You can also reject emitThen
by throwing an error from a handler:
emitter ;