Using subscribeOn with retrofit

There is conflicting information about when and whether to use subscribeOn using Retrofit.

Here is the answer saying not to use subscribeOn .
Here is an answer that seems to imply that subscribeOn does not have a good default set.
Here is sample code using subscribeOn .

So, once for all, when should I use subscribeOn and with which stream? What are the possible consequences of using or not using subscribeOn ?

 apiService.issueRequest() // Is this useful? Required? Bad practice? .subscribeOn(Schedulers.io()) // Do actions on main thread .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Action1<Response>() { @Override public void call(Response response) { handleResponse(response); }); 
+6
source share
1 answer

In the current version of Retrofit (1.9.0), Retrofit uses its own executor to make an HTTP call and does not use an executor supported by the schedulers specified by the subscribeOn method.

In your case, the scheduler will only be used to execute code that will add your HTTP call to the executor used during the modification. (So ​​it's a little useless ...)

BUT , regarding the actual code from “Retrofitting on Github” , retrofit it with an executor so that it can use the RxJava scheduler.

+6
source

Source: https://habr.com/ru/post/982343/


All Articles