Skip to Content
Hands-On Reactive Programming with Python
book

Hands-On Reactive Programming with Python

by Romain Picard
October 2018
Intermediate to advanced
420 pages
10h 26m
English
Packt Publishing
Content preview from Hands-On Reactive Programming with Python

Operators – ref_count and share

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Programming with Design Patterns

Python Programming with Design Patterns

James W. Cooper

Publisher Resources

ISBN: 9781789138726Supplemental Content