Today's discussion with +Thomas Keller
forced me rethink the way I explain how subscribeOn()
operators work and I believe I found a short and easy to remember explanation.
Typically we create an Observable instance by implementing OnSubscribe.call()
method where we receive an instance of subscriber
, do some work and send required events to that subscriber. This is the place where a scheduler defined by subscribeOn()
applies. Because there is only one such place, we can only use a single scheduler for code execution, although subscribeOn()
operator can be defined multiple times at any place of the chain.
All the others chained operators like map()
etc. are some kind of observers
for the events our "almighty" Observable instance sends. For each of those operators in the chain we can define a separate scheduler using observeOn()
operator right before them. That's why we can have many of observeOn()
operators and all of them will be applied to follow-up operators in the chain.
Now the marble diagram down below makes sense to me... once again ;)#rxjava #androiddev #androidtips