promisify-event
v1.0.0
Published
Promisify EventEmitter's event.
Downloads
952,172
Maintainers
Readme
promisify-event
Promisify EventEmitter's event.
Install
npm install promisify-event
Usage
const promisifyEvent = require('promisify-event');
// Promisify server's `listening` event:
promisify(server, `listening`).then(() => {
// ...
});
// Promisify `error` event. `error` event always rejects the promise:
promisify(server, 'error').catch(() => {
// ...
});
// Cancel event subscription and promise (it will be never fulfilled):
var listeningPromise = promisify(server, `listening`);
listeningPromise.cancel();
listeningPromise.then(() => {
// Will never happen
});