I have this barebones example not behaving as I expect based on the documentation of rxjs. I would expect the subscriptions to both receive all values.
The docs mention:
Two observers then subscribe to this sequence and print out its values. You will notice that the sequence is reset for each subscriber, in which the second subscription will restart the sequence from the first value.
let s1 = rx.Observable.from([1, 2, 3, 4, 9, 11])
s1.subscribe(
x => console.log(x),
x => console.log(x),
x => console.log('complete'))
s1.subscribe(
x => console.log(x),
x => console.log(x),
x => console.log('complete'))
However the second subscription just logs 'complete'
As it turns out the example works as expected in rxjs 2.4, but not in 2.3. Does anyone know what changed? I cannot spot it in the release notes
Here is a jsfiddle with 2.3.20: fiddle
and here is one with 2.4.1: fiddle
This not right behavior for a cold observable. An observable which created from an array is cold observable and cannot share subscription more than on one observer. For correct work you can transform your observable to a hot observable. You can look on this documentation http://xgrommx.github.io/rx-book/content/observable/observable_instance_methods/publish.html. In your case you could use something like this http://jsbin.com/mowaco/edit?js,console. Now both subscriptions working parallel.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With