https://github.com/noomorph/node-async-iterators-kit
https://github.com/noomorph/node-async-iterators-kit
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/noomorph/node-async-iterators-kit
- Owner: noomorph
- License: mit
- Created: 2018-11-01T10:19:49.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-01T11:58:34.000Z (over 7 years ago)
- Last Synced: 2025-03-17T10:53:27.191Z (over 1 year ago)
- Language: TypeScript
- Size: 61.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# node-async-iterators-kit
[](https://badge.fury.io/js/async-iterators-kit)
[](https://opensource.org/licenses/MIT)
[](https://travis-ci.org/noomorph/node-async-iterators-kit)
## Install
```
npm install async-iterators-kit
```
## Use
Currently, the package provides a set of async iterators for handling readline, streams, child process stdout and timeouts:
* [ChildProcessStdioAsyncIterator](lib/ChildProcessStdioAsyncIterator.ts)
* [ReadlineAsyncIterator](lib/ReadlineAsyncIterator.ts)
* [StreamReadlineAsyncIterator](lib/StreamReadlineAsyncIterator.ts)
* [TimeoutAsyncIterator](lib/TimeoutAsyncIterator.ts)
See example:
```javascript
const node = cp.spawn('node', ['-p', '2+2'], { stdio: 'pipe' });
const iterator = new ChildProcessStdioAsyncIterator(node, 'stdout');
for await (const line of iterator) {
lines.push(line); // [4]
break; // sends SIGTERM to the process if it has not exited yet
}
```