-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Closed
Description
Hi, I am using RxJava 2.1.1. I thought I knew how subscribeOn
works, but sometimes I still have some doubts about it.
As far as I know, for subscribeOn
it doesn't metter the position where you use it (in the chain).
Assuming that I am executing this code from my MAIN THREAD.
Observable.just("")
.doOnSubscribe(/* NEW THREAD */)
.subscribeOn(Schedulers.newThread())
.subscribe(/* NEW THREAD */);
As expected the doOnSubscribe()
is called on the NEW THREAD, because of subscribeOn(Schedulers.newThread())
But, if I call subscribeOn
before doOnSubscribe
the result will be different:
Observable.just("")
.subscribeOn(Schedulers.newThread())
.doOnSubscribe(/* MAIN THREAD */)
.subscribe(/* NEW THREAD */);
Now the doOnSubscirbe()
seems to be executed in the MAIN THREAD, regardless of subscribeOn(Schedulers.newThread())
.
Why is this happening?
eoinahernBDSwiss, IslamSalah, dtchepak, petersamokhin, tir38 and 7 moreps-feng, esanz91, bryen95, tir38, ericntd and 1 more