RxSwift: subscribeOn vs observeOn?

Aaina jain
Swift India
Published in
2 min readNov 30, 2018
Credit: unsplash.com

subscribeOn:

It allows you to change the scheduler on which the subscription code will be executed. subscribeOn changes the thread for the calls prior to it and also the methods that follow it. Order doesn’t matter, subscribeOn can be placed anywhere.

observeOn:

It allows you to change the scheduler on which the observer code will be executed.

Let’s understand about both:

observeOn works only downstream

subscribeOn Position doesn’t matter. It works downstream and upstream

Consecutive subscribeOn do not change the thread

Consequent observeOn do change the thread

Thread change by an observeOn cannot be overridden by a subscribeOn

There is a nice article in RxJava if you are interested to explore more:

http://tomstechnicalblog.blogspot.com/2016/02/rxjava-understanding-observeon-and.html

You can catch me at:

Linkedin: Aaina Jain

Twitter: __aainajain

If you have any suggestions for the next post write to me at aainajain100@gmail.com.

--

--