This package wraps an event emitter object and returns a bluebird promise that is either resolved, rejected, or canceled based on what events are fired from the emitter.
npm install bluebird-events
var bluebirdEvents = require('bluebird-events');
var someEmitter = new TestEmitter();
var promise = blueBirdEvents(someEmitter, {
resolve: 'success-event-name',
reject: ['error-event-name', 'error-event-name-2'],
cancel: 'cancel-event-name' // by passing cancel the promise is made cancelable
});
// Will resolve the promise
someEmitter.emit('success-event-name');
//Will reject promise with the given error
someEmitter.emit('error-event-name', new Error('Some Error Occurred!'));
//Will also reject promise with the given error
someEmitter.emit('error-event-name-2', new Error('Some Other Error Occurred!'));
This library is dependent upon bluebird
, but because bluebird
is so common, there is no need to install it multiple times so bluebird
is declared as a peerDependency
Note: bluebird
is also declared as a devDependency
for running the test suite