I'm trying to construct an observable from a chain of API calls but I can't get it to work. What I have is four API calls ApiA
, ApiB
, ApiC
and ApiD
that return Observables using RxJavaCallAdapterFactory
. ApiA
and ApiB
have to be called first and then after both are executed ApiC and ApiD should be called. After last two are executed View is initialized. I'm using zip operator for waiting to calls to finish, I'm not sure that's the way to go but I'm quite new to RxJava
so if there is another and better way to do that please let me know.
Below is my code with comments showing where I got stuck
public Observable syncData() {
return Observable.zip(
// these two calls are executed
callApiA(),
callApiB(),
(o, o2) -> Observable.zip(
/* these two calls are not executed, it seems as if this zip has
no subscriber but i don't know why ... */
callApiC(),
callApiD(),
(o, o2) -> {
someLogic();
return Observable.empty();
}));
}
And in view I just subsribe to this method
viewModel.syncData().subscribe(
o -> mainAdapter.update(),
throwable -> throwable.printStackTrace()
);
Again I'm fairly new to RxJava so any help will be appreciated. thanks
.subscribeOn(Schedulers.io())
oncallApiX()
for that. Do you have some log? – Kevin Robatel