Hullo JS
Search…
ofEventEmitter
import { ofEventEmitter } from '@hullo/node'
ofEventEmitter wraps an EventEmitter and sends value and completion signals according to value event name and completion event name. Does not have any back-pressure mechanism built in.
Following example echos any input and ends the program when user enters "end".
1
import {
2
ofEventEmitter
3
} from '@hullo/node';
4
​
5
ofEventEmitter(process.stdin, "data", "end")
6
.subscribe({
7
next: ([buf]) => {
8
const line = new TextDecoder("utf-8").decode(buf);
9
console.log(line);
10
if (line === "end\n") {
11
process.exit();
12
}
13
},
14
complete: () => {
15
process.exit();
16
}
17
});
Copied!
Although it is an example, it is recommended to deal with Node streams through ofReadableStream.
Last modified 2yr ago
Copy link