Understanding observeOn()

The subscribeOn() operator instructs the source Observable which Scheduler to emit emissions on. If subscribeOn() is the only concurrent operation in an Observable chain, the thread from that Scheduler will work the entire Observable chain, pushing emissions from the source all the way to the final Observer. The observeOn() operator, however, will intercept emissions at that point in the Observable chain and switch them to a different Scheduler going forward.

Unlike subscribeOn(), the placement of observeOn() matters. It leaves all operations upstream on the default or subscribeOn()-defined Scheduler, but switches to a different Scheduler downstream. In the following example, an Observable emits a series of strings ...

Get Learning RxJava - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.