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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.