https://github.com/parro-it/ai-event
Create an async iterable from an event emitter.
https://github.com/parro-it/ai-event
Last synced: 10 months ago
JSON representation
Create an async iterable from an event emitter.
- Host: GitHub
- URL: https://github.com/parro-it/ai-event
- Owner: parro-it
- License: mit
- Created: 2017-11-17T19:42:50.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-05T20:30:59.000Z (about 8 years ago)
- Last Synced: 2024-09-17T04:36:51.455Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 306 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: license
Awesome Lists containing this project
README
# ai-event
[](http://travis-ci.org/parro-it/ai-event)
[](https://npmjs.org/package/ai-event)
> Create an async iterable from an event emitter.
This module transform an event emitter into an async iterable.
## Async iterable fun
**This module is part of
[Async iterable fun](https://github.com/parro-it/ai-fun), a complete toolset of
modules to work with async iterables.**
## Usage
Transform a node stream into an aync iterable:
```js
const fromEvent = require("ai-event");
import { createReadStream } from "fs";
const stream = createReadStream("aFile", "utf8");
const iterable = fromEvent(stream, "data");
for await (const chunk of iterable) {
console.log(chunk);
}
```
This will output aFile content
## API
### aiFromEvent
Create from an event emitter an async iterable that emits
each event received.
**Parameters**
- `emitter` **EventEmitter** the emitter to listen for events
- `event` **[String](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of event to bind to write
Returns **AsyncIterable** converted iterator
## Install
With [npm](https://npmjs.org/) installed, run
```bash
npm install --save ai-event
```
## See Also
- [`noffle/common-readme`](https://github.com/noffle/common-readme)
- [`parro-it/ai-fun`](https://github.com/parro-it/ai-fun)
## License
MIT