How to use schedulers – subscribeOn and observeOn operators
Now that we have gained some grip on what schedulers are, how many types of schedulers are available, and how to create a scheduler
instance, we will focus on how to use schedulers.
There are basically two operators that help us implement schedulers. Up until now, in this chapter, we've used the subscribeOn
operator in all the examples with a scheduler; however, there's another operator—observeOn
. We will now focus on these two operators, learning how they work, and how they differ.
Let's start with the subscribeOn
operator.
Changing thread on subscription – subscribeOn operator
We need to understand how the Observable
works before delving any further in how to use scheduler. Let's take a look at the following graphics:
As the preceding image depicts, it's the threads that are responsible for carrying items from the source all the way to the Subscriber through operators. It may be a single thread throughout the subscription, or it may...