ObserveOn and SubscribeOn Operators

Learn how the ObserveOn and SubscribeOn Operators can be used with Schedulers.

In the previous section, we used the observeOn operator to change the Scheduler in some Observables. The observeOn and subscribeOn operators are instance operators that return a copy of the Observable instance, but which use the Scheduler we pass as a parameter.

The observeOn operator takes a Scheduler and returns a new Observable which then uses that Scheduler. This makes every onNext call run in the new Scheduler.

The subscribeOn operator forces the subscription and unsubscription work (not the notifications) of an Observable to run on a particular Scheduler. Like the observeOn operator, it accepts a Scheduler as a parameter. The subscribeOn operator is useful when, for example, we’re running in the browser and doing significant work in the subscribe call but we don’t want to block the UI thread with it.

Get hands-on with 1400+ tech skills courses.