# await-event

> yield an event with generators

Latest version **2.1.0** (published 2017-03-24) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.0 |
| Published | 2017-03-24 |
| First published | 2014-04-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Jonathan Ong |
| Maintainers | coderhaoxin, dead-horse, dead_horse, fengmk2, jongleberry |
| Keywords | co, events, event-emitter, await |

## Links

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

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 2.1.0 (latest) — 2017-03-24
- 2.0.0 — 2017-02-16
- 1.0.0 — 2014-04-24

## README

# Await Event

A really stupid utility I use frequently for event emitters.
Allows you to `yield` an event and return the results.
I use this a lot of locking.

Note: you probably shouldn't use this for the `error` event.

## Example

```js
var PassThrough = require('stream').PassThrough

var stream = new PassThrough()
// you attach it directly on an event emitter
stream.await = require('await-event')

co(function* () {
  var chunk = yield stream.await('data')
  var chunk = yield stream.await('data')
  var chunk = yield stream.await('data')
}).catch(noop)

stream.write('some chunk')
```

You can use awaitEvent without attach on an event emitter:

```js
var EventEmitter = require('event')

var emitter = new EventEmitter()
co(function*() {
  yield awaitEvent(emitter, 'ready')
}).catch(noop)
```

When use this for `error` event, it will reject once `error` event emitted:

```js
var EventEmitter = require('event')

var emitter = new EventEmitter()
co(function*() {
  // it will throw when `error` event emitted
  yield awaitEvent(emitter, 'error')
}).catch(err => console.error(err.stack))
```

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