我已經刪除的樣板去點rxjs zip不是懶惰?
// a.js
// My observables from stream and event
this.a = Rx.Node.fromStream(this.aStream());
this.itemSource = Rx.Observable.fromEvent(ee, 'addItem');
// Zip 'em
this.itemcombo = Rx.Observable.zip(this.a, this.itemSource, function (s1, s2) {
return {item: s2, a: s1.toString()};
});
// Streams the lowercase alphabet
rb.prototype.aStream = function aStream() {
var rs = Readable();
var c = 97;
rs._read = function() {
rs.push(String.fromCharCode(c++));
console.log('Hit!');
if (c > 'z'.charCodeAt(0)) {
rs.push(null);
}
};
return rs;
};
// b.js
(需要上面導出模塊)
rb.enqueue('a'); // The method simply does an ee.emit('addItem', ...) in the module to trigger the itemSource observable
我期望看到:
{item: 'a', a: 'a'}
印在控制檯
發生了什麼事:
Hit!
是{item: 'a', a: 'a'}
之前印刷24次。這意味着zip
已從aStream
中取得所有值,將它們緩存起來,然後執行它應該執行的操作。
我該如何獲得相同的功能zip
優惠但懶惰?我的目標是使用無限流/可見性,並將其與有限(異步)壓縮在一起。通過可運行
編輯
查看/編輯:RX Zip test編輯基於答案更新2代碼 - >沒有輸出了。
請加回樣板和簡化的例子。 – 2014-08-27 12:50:58
http://www.yoda.arachsys.com/csharp/complete.html – 2014-08-27 12:51:23
@DaveSexton請參閱:http://pastebin.com/mnc82KuV和http://pastebin.com/8HxURWYc複製/粘貼/運行版本- 謝謝!我不認爲這個例子可以更簡化。這是2個流和zip功能。我已經包含了我用作參考的那個流,它可能已被排除,忽略該部分是安全的,但認爲它可能是有用的。 – rollingBalls 2014-08-27 13:04:04