1.0.1 • Published 3 years ago

await-event-or-error v1.0.1

Weekly downloads
51
License
MIT
Repository
github
Last release
3 years ago

Actions Status

await-event-or-error

Returns a Promise that resolves on an event or rejects on an error.

Examples

Pass an EventEmitter and an event to be watched.

await awaitEventOrError(emitter, "connected");

The function can be added to an EventEmitter to allow only passing the event.

emitter.eventOrError = awaitEventOrError;
await emitter.eventOrError("connected");

The promise will reject on an "error" event by default, but you can specify a different error event.

await emitter.eventOrError("connected", "responseError");

If the event emits values they will be returned in an array.

const values = await emitter.eventOrError("connected");
...
emitter.emit("connected", 1, 2);
...
// values === [1, 2]