October 2018
Intermediate to advanced
420 pages
10h 26m
English
There are cases wherein calling the connect method at the correct time is not easy, or is not necessary. In many cases, a cold observable can be converted to a hot observable whenever a first observer subscribes to it, as long as some subscriptions are ongoing. The ref_count operator does just that: it converts a cold observable to a hot observable as soon as a first subscription occurs. Its prototype is as follows:
ConnectableObservable.ref_count(self)
It is a method of the ConnectableObservable class. So, it must be used after a call to publish, as follows:
numbers = Observable.from_([1,2,3])pub_numbers = numbers.publish().ref_count()pub_numbers.subscribe( on_next=lambda i: print("item: {}".format(i)), on_error=lambda ...