Understanding subscribeOn()

We kind of touched on using subscribeOn() already, but in this section, we will explore it in more detail and look at how it works.

The subscribeOn() operator will suggest to the source Observable upstream which Scheduler to use and how to execute operations on one of its threads. If that source is not already tied to a particular Scheduler, it will use the Scheduler you specify. It will then push emissions all the way to the final Observer using that thread (unless you add observeOn() calls, which we will cover later). You can put subscribeOn() anywhere in the Observable chain, and it will suggest to the upstream all the way to the origin Observable which thread to execute emissions with.

In the following example, ...

Get Learning RxJava 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.