I have a SyncService.
@Override
public int onStartCommand(Intent intent, int flags, final int startId) {
Timber.i("Starting sync...");
...
RxUtil.unsubscribe(mSubscription);
mSubscription = mDataManager.syncEvents()
.subscribeOn(Schedulers.io())
.subscribe(new Observer<Event>() {
@Override
public void onCompleted() {
Timber.i("Synced successfully!");
stopSelf(startId);
}
@Override
public void onError(Throwable e) {
Timber.w(e, "Error syncing.");
stopSelf(startId);
}
@Override
public void onNext(Event event) {
}
});
return START_STICKY;
}
Observable events = mDataManager.syncEvents() is an API call.
I want to do a parallel call:
Single userInfo = mDataManager.getUserInfo()
and call stopSelf(startId); after these two calls will finish.
How can I do it?
I tried RxJava Fetching Observables In Parallel but this is a little different case.
I think I have to use .zip or .merge method. But in my case one method call returns Observable (list on Events) and second Single (one UserInfo object).
I created z result class which could be a result of .zip method, but I don't know how to fill it:
public class SyncResponse {
List<Event> events;
UserInfo userInfo;
...
}