npm.io
1.0.1 • Published 11 years ago

promise-event-before

Licence
MIT
Version
1.0.1
Deps
1
Vulns
0
Weekly
0

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

Keywords