# event-emitter-promisify

> Utility to resolve EventEmitters as a promise

Latest version **1.1.0** (published 2022-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install event-emitter-promisify
pnpm add event-emitter-promisify
yarn add event-emitter-promisify
bun add event-emitter-promisify
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-02-17 |
| First published | 2022-02-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jesse Wright |
| Maintainers | jeswr |
| Keywords | promise, eventemitter, promisify, event, emitter, async |

## Links

- npm: https://www.npmjs.com/package/event-emitter-promisify
- Repository: https://github.com/jeswr/promisify-event-emitter
- Homepage: https://github.com/jeswr/promisify-event-emitter#README.md
- Issues: https://github.com/jeswr/promisify-event-emitter/issues
- npm.io page: https://npm.io/package/event-emitter-promisify

## 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.1.0 (latest) — 2022-02-17

## README

# event-emitter-promisify
Utility to resolve EventEmitters as a promise

[![GitHub license](https://img.shields.io/github/license/jeswr/promisify-event-emitter.svg)](https://github.com/jeswr/promisify-event-emitter/blob/master/LICENSE)
[![npm version](https://img.shields.io/npm/v/event-emitter-promisify.svg)](https://www.npmjs.com/package/event-emitter-promisify)
[![build](https://img.shields.io/github/workflow/status/jeswr/promisify-event-emitter/Node.js%20CI)](https://github.com/jeswr/promisify-event-emitter/tree/main/)
[![Dependabot](https://badgen.net/badge/Dependabot/enabled/green?icon=dependabot)](https://dependabot.com/)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)

## Usage

By default `promisifyEventEmitter` returns a promise which resolves to undefined if the `end` event is called, and rejects if the `error` event is called.

```ts
import { promisifyEventEmitter } from 'event-emitter-promisify'

const stream = new Readable();
stream.push(null);
await promisifyEventEmitter(stream.on('data', () => {}));
```

The return value on `end` can also be customized. For instance:

```ts
export default function arrayifyStream<T = any>(stream: EventEmitter): Promise<T[]> {
  const array: T[] = [];
  return promisifyEventEmitter(stream.on('data', data => array.push(data)), array);
}
```

## License
©2022–present
[Jesse Wright](https://github.com/jeswr),
[MIT License](https://github.com/jeswr/promisify-event-emitter/blob/master/LICENSE).

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