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".

import {
ofEventEmitter
} from '@hullo/node';
ofEventEmitter(process.stdin, "data", "end")
.subscribe({
next: ([buf]) => {
const line = new TextDecoder("utf-8").decode(buf);
console.log(line);
if (line === "end\n") {
process.exit();
}
},
complete: () => {
process.exit();
}
});

Although it is an example, it is recommended to deal with Node streams through ofReadableStream.