"采取" observable隐含完成?

时间:2015-05-28 10:56:37

标签: rxjs

具有
obs1 = new Rx.Observable.interval(1000); obs2 = obs1.take(2);
obs2发出的第二个值之后,obs1将完成 怎么样obs1
它会完成还是继续射击?

1 个答案:

答案 0 :(得分:0)

take运算符返回一个新的可观察序列,该序列对Rx.Observable.interval生成的源可观察序列的操作没有影响。由于Rx.Observable.interval是一个“热门”可观察对象,obs1即使在obs2完成后也会继续发出值。

var obs1 = Rx.Observable.interval(1000);
obs1.subscribe(function(x) { document.write("obs1: " + x + '<br \>'); }, null, function(x) { document.write("obs1 completed" + '<br \>'); });
var obs2 = obs1.take(2);
obs2.subscribe(function(x) { document.write("obs2: " + x + '<br \>'); }, null, function(x) { document.write("obs2 completed" + '<br \>'); });
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/2.5.2/rx.all.min.js"></script>