我已经删除的样板去点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