O'Reilly logo

Learning RxJava by Thomas Nield

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required