Skip to content

Does subscribeOn call order matter? #5459

@Joseph82

Description

@Joseph82

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions