# await-event-or-error

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

Latest version **1.0.1** (published 2021-02-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install await-event-or-error
pnpm add await-event-or-error
yarn add await-event-or-error
bun add await-event-or-error
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-02-24 |
| First published | 2019-02-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Tony Brix |
| Maintainers | tonybrix |
| Keywords | events, EventEmitter, Promise |

## Links

- npm: https://www.npmjs.com/package/await-event-or-error
- Repository: https://github.com/UziTech/await-event-or-error
- Homepage: https://github.com/UziTech/await-event-or-error#readme
- Issues: https://github.com/UziTech/await-event-or-error/issues
- npm.io page: https://npm.io/package/await-event-or-error

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-02-24
- 1.0.0 — 2019-02-28

## README

[![Actions Status](https://github.com/UziTech/await-event-or-error/workflows/CI/badge.svg)](https://github.com/UziTech/await-event-or-error/actions)


# 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.

```js
await awaitEventOrError(emitter, "connected");
```

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

```js
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.

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

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

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

---
_Source: https://npm.io/package/await-event-or-error · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
