promise-event-before
v1.0.1
Published
A tool that returns a promise that resolves if an EventEmitter emits an event before the given timeout
Downloads
1
Readme
promise-event-before
A tool that returns a promise that resolves if an EventEmitter emits an event before the given timeout
Installation
npm install promise-event-before
Usage
var diceRollEmitter = ...
var eventBefore = require('promise-event-before');
eventBefore(emitter, 'rolled', 1000).then(function(emittedValue) {
console.log('dice roll:', roll);
}, function(err) {
console.error(err);
});
API
eventBefore(emitter, eventName, timeout) : Promise
emitter
an EventEmitter to inspect
eventName
the event name to wait for
timeout
the number of milliseconds to wait before declaring the Promise rejected