Skip to content

Instantly share code, notes, and snippets.

View craPkit's full-sized avatar

Patrick Nemenz craPkit

  • adesso Austria
  • Vienna, Austria
View GitHub Profile
@craPkit
craPkit / promised-event-with-timeout.js
Last active March 18, 2019 12:13 — forked from simongregory/promised-event-with-timeout.js
Wrap a Javascript event in a Promise with a time out.
/**
* Race one or more event types to resolve a returned promise.
*
* Automatically handles event binding and removal and supports a common timeout for all event types.
*
* @param {!Node} emitter the node which is expected to fire one of the event types
* @param {!String|!Array<String>} eventTypes the event types which participate in the race
* @param {Number?} timeout=600000 the length of the timeout which also participates in the race
* @returns {Promise} that resolves upon completing the race
*/

Keybase proof

I hereby claim:

  • I am craPkit on github.
  • I am crapkit (https://keybase.io/crapkit) on keybase.
  • I have a public key whose fingerprint is 2110 7D3C E5D4 206A 15E5 7BBA 3ACA DF66 CE02 8254

To claim this, I am signing this object: