Observing on a different thread – observeOn operator

While subscribeOn looks like an awesome gift from heaven, it may not be suited in some cases. For example, you may want to do computations on the computation threads and display the results from the io threads, which actually you should do. The subscribeOn operator requires a companion for all these things; while it'll specify the thread for the entire subscription, it requires its companion to specify threads for specific operators.

The perfect companion to the subscribeOn operator is the observeOn operator. The observeOn operator specifies the scheduler for all the operators called after it.

Let's modify our program with observeOn to perform the map operation in the Schedulers.computation() ...

Get Reactive Programming in Kotlin 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.