如何使用 Rx 监听 NodeJS 事件?
我的 JakeJS 文件中有以下代码。
process.on("cmdStart", () => {
console.log("> " + command)
});
我想以 RxJS 风格来做,但我不确定什么是最好的方法。
我已经阅读了文档并尝试了他们在 github 上提供的一些示例,但我不太确定,它似乎不起作用,这是我尝试过的。
const eventEmitter: any = new EventEmitter();
const cmdStart = Rx.Observable.fromEvent(eventEmitter, "cmdStart");
const subscription = cmdStart.subscribe(function (command) {
console.log("> " + command)
});
eventEmitter.emit(command);