Summary
In this chapter, you have learned about multicasting using ConnectableObservable and Subject. The biggest takeaway is that Observable operators result in separate streams of events for each Observer that subscribes to it. If you want to consolidate these multiple streams into a single stream to prevent redundant work, the best way is to call publish() on an Observable to yield ConnectableObservable. You can then manually call connect() to fire emissions once your observers are set up or automatically trigger a connection using autoConnect() or refCount().
Multicasting also enables replaying and caching, so a tardy Observer can receive missed emissions. A Subject object provides a way to multicast and cache emissions as well, but you ...
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.
Read now
Unlock full access