1.0.2 • Published 7 years ago

promised-event v1.0.2

Weekly downloads
9
License
-
Repository
github
Last release
7 years ago

promised-event

License Build status

Simply get a promise for a specified event

Promises the next dispatch of a specified EventEmitter event. Nothing more, nothing less.

Installation & usage

npm install promised-event
cosnt promiseEvent = require('promised-event');
const emitter = new EventEmitter();
promiseEvent(emitter, 'myevent').then((answer) => {
    console.log(answer);
});
emitter.emit('myevent', 42);
// 42

Want to reject on error?

Simply do

const promise = promiseEvent(stream, 'error').then(Promise.reject);

Then you can write

promise.catch((err) => {
    console.log('oh no!');
});

API

promiseEvent(emitter, eventName)

License

MIT