events-bluebird
This is a lightweight wrapper for native node events.
Adds EventEmitter.prototype.emitAsyncSeries
& EventEmitter.prototype.emitAsyncParallel
methods. The API reflects native EventEmitter
API with the following necessary changes:
- Added methods return a Promise object which when fulfilled, returns
true
if the event had listeners, false
otherwise - node's deprecated domain feature is not supported
Installation
npm install events-bluebird
Example
var EventEmitter = require('events-bluebird').EventEmitter;
var emitter = new EventEmitter;
emitter.on('event', function(param) {
return new Promise(function(resolve, reject) {
setTimeout(function() {
console.log('first');
return resolve();
}, 500);
});
});
emitter.on('event', function(param) {
console.log('later');
});
emitter.emitAsyncSeries('event', 'param').then(function(hadListeners) {
console.log(hadListeners);
});
Tests
npm test