Skip to content

Tiny node EventEmitter wrapper which implements `emitAsync` & `emitAsyncParallel` methods.

License

Notifications You must be signed in to change notification settings

fogine/events-bluebird

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

events-bluebird

Build Status Test Coverage

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);//true
});

// Output:
// first
// later
// true

Tests

npm test

About

Tiny node EventEmitter wrapper which implements `emitAsync` & `emitAsyncParallel` methods.

Resources

License

Stars

Watchers

Forks

Packages

No packages published