Difference between Subject and ConnectableObservable/Multicast?

785 views
Skip to first unread message

Matthias

unread,
Mar 18, 2013, 5:39:39 AM3/18/13
to rxj...@googlegroups.com
Hi,

in an earlier discussion we came to the conclusion that for a connect/unconnect scenario in our app we would require the Multicast operator and a new type called ConnectableObservable, which is scheduled for 0.7: https://github.com/Netflix/RxJava/issues/65

I've just about starting working more with the Subject class and found it immensely useful, since it allows you to implement a simplistic event bus in just a few lines of code. Looking at the implementation of Subject, I'm not sure I understand what Multicast would do that Subject doesn't already do? Subject acts like a connectable observable, since its onSubscribe function simply adds an observer to a list of observables, and unsubscribe does the reverse. In onNext, it then simply forwards to onNext of each observable.

Isn't this exactly the connect/disconnect behavior IConnectableObservable and Multicast solve too? If I want to receive callbacks, I subscribe to the subject *without* actually triggering that observable. I can unsubscribe and resubscribe at any point in time to stop/start receiving callbacks. I could therefore use Subject as a proxy between a long running observable that performs a job and produces results, and then forward these results to any potential observers by sending them to the Subject proxy.

Or am I misunderstanding the purpose of the two?

Thanks,
Matthias

Ben Christensen

unread,
Mar 18, 2013, 1:36:39 PM3/18/13
to rxj...@googlegroups.com
I'm still coming up to speed on the details of this topic myself, but my understanding is that these operators use Subjects just with different behaviors in when they are connected, whether it's automatic or not, etc.

The existing Subject class will probably allow you to do most or all of this, the operators I think will be reusable versions of some of the boilerplate that you'll probably build up while using Subject.

But like I said ... this is a new area of work for me on Rx so I'm speaking at the edge of my understanding right now so may have mis-stated some things.

Matthias

unread,
Mar 20, 2013, 5:11:47 AM3/20/13
to rxj...@googlegroups.com
That's what I suspected, i.e. Multicast would probably be implemented in terms of Subject.

Thanks for chiming in though, really excited to see this project moving forward!
Reply all
Reply to author
Forward
0 new messages