Rxjs - Observable - Cold To Hot

Sample

Cold 的是谁订阅,不管你什么时候订阅,都能拿到同样的东西,有单独的数据流

Hot 所有订阅者是共享的,你订阅晚了,之前的数据你是拿不到的

var interval = Rx.Observable.interval(1000);

var source = interval
.take(10)
.do(function (x) {
console.log('Side effect');
});

var published = source.publish().refCount();

published.subscribe(x=>console.log('SourceA',x));

setTimeout(function() {
published.subscribe(x=>console.log('SourceN',x));
}, 5000);
Side effect
SourceA 0
Side effect
SourceA 1
Side effect
SourceA 2
Side effect
SourceA 3
Side effect
SourceA 4
Side effect
SourceA 5
SourceN 5
Side effect
SourceA 6
SourceN 6
Side effect
SourceA 7
SourceN 7
Side effect
SourceA 8
SourceN 8
Side effect
SourceA 9
SourceN 9