Summary
In this chapter, we covered multicasting using ConnectableObservable and Subject. The biggest takeaway is that Observable operators result in separate streams of events for each Observer that subscribes. 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().
Mutlicasting also enables replaying and caching, so tardy Observers can receive missed emissions. Subjects provide a means to multicast and cache emissions as well, but you should only utilize them ...
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