Default Schedulers for rxjava on Android

前端 未结 4 498
予麋鹿
予麋鹿 2021-01-01 20:32

I\'m using Retrofit to return rxjava Observable\'s for my async network calls.

I find myself repeating the following invocation:

someApiCall().subscrib

4条回答
  •  伪装坚强ぢ
    2021-01-01 21:11

    it is not the full answer to what you are looking for, but this at least removes the burden of righting subscribeOn(Schedulers.io())

    retrofit = new Retrofit
                .Builder()
                .baseUrl(app.getUrlBase())
                .client(httpClient)
                .addCallAdapterFactory(
    RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()) // <-- default subscribeOn() 
    )
                    .addConverterFactory(jsonFactory)
                    .build();
    

提交回复
热议问题