Tomek Polański
1 min readMay 19, 2017

--

Hey Edio,
the issue you are having is quite frequent one.
Let’s only focus on the first line:

Observable.just(this.method())

Because just as a parameter gets value and not function, we can rewrite the method like this:

boolean result = this.method();
Observable.just(result);

Not we can see that the this.method is executed before it has anything to do with Rx. This means that it will be executed on whatever thread the parent method is executed.

To execute the method in a thread specified by Rx, we need to use fromCallable:

Observable.fromCallable(() -> method())

or with method reference:


Observable.fromCallable(this::method)

This way method will be run on the thread you specify in onSubscribe.

Hope you get a clearer picture now.

--

--

Tomek Polański
Tomek Polański

Written by Tomek Polański

Passionate mobile developer. One thing I like more than learning new things: sharing them

Responses (1)