# async-stream-emitter

> An alternantive to EventEmitter using consumable streams.

Latest version **7.0.1** (published 2023-10-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-stream-emitter
pnpm add async-stream-emitter
yarn add async-stream-emitter
bun add async-stream-emitter
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 7.0.1 |
| Published | 2023-10-20 |
| First published | 2018-11-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/async-stream-emitter) |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jonathan Gros-Dubois |
| Maintainers | topcloudsystems |
| Keywords | iterable, async, stream, event, emitter, for-await-of |

## Links

- npm: https://www.npmjs.com/package/async-stream-emitter
- Repository: https://github.com/SocketCluster/async-stream-emitter
- Homepage: https://github.com/SocketCluster/async-stream-emitter#readme
- Issues: https://github.com/SocketCluster/async-stream-emitter/issues
- npm.io page: https://npm.io/package/async-stream-emitter

## Dependencies (1)

- [stream-demux](https://npm.io/package/stream-demux.md) ^10.0.1

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

- 7.0.1 (latest) — 2023-10-20
- 7.0.0 — 2023-10-20
- 6.0.1 — 2023-09-07
- 6.0.0 — 2023-09-07
- 5.0.0 — 2023-09-06
- 4.1.0 — 2022-10-10
- 4.0.0 — 2020-02-07
- 3.0.3 — 2019-03-17
- 3.0.2 — 2019-03-02
- 3.0.1 — 2019-02-24
- 3.0.0 — 2019-02-24
- 2.1.0 — 2019-02-21
- 2.0.0 — 2019-01-17
- 1.1.0 — 2018-12-23
- 1.0.2 — 2018-12-23
- … 2 more at https://npm.io/package/async-stream-emitter/versions

## README

# async-stream-emitter
EventEmitter using ConsumableStream.

## Main methods:

- emit(eventName, data)
- listener(eventName)
- closeListener(eventName)
- closeAllListeners()
- killListener(eventName)
- killAllListeners()
- getListenerBackpressure(eventName)
- getAllListenersBackpressure()

## Usage examples

```js
let emitter = new AsyncStreamEmitter();

(async () => {
  await wait(10);
  emitter.emit('foo', 'hello');

  // This will cause all for-await-of loops for that event to exit.
  // Note that you can also use the 'break' statement inside
  // individual for-await-of loops.
  emitter.closeListener('foo');
})();

(async () => {
  for await (let data of emitter.listener('foo')) {
    // data is 'hello'
  }
  console.log('The listener was closed.');
})();

// Utility function.
function wait(duration) {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, duration);
  });
}
```

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