如何在代碼中稍後創建observable並生成下一個值?我希望能夠通過其他異步事件從代碼的不同部分調用onNext。將觀察者存儲在全局變量中並稍後使用
這是我已經盡力了,這是不行的:
var Rx = require('rx');
var GlobalObserver;
var source = Rx.Observable.create(observer => {
GlobalObserver = observer;
});
var subscription = source.subscribe(
x => console.log('onNext: %s', x),
e => console.log('onError: %s', e),
() => console.log('onCompleted')
);
//...later in the code, as a result of another async event:
GlobalObserver.onNext(someData);
...
GlobalObserver.onNext(someOtherData);
這絕對應該是一個評論,不是答案。 – DavidDomain