I am using retrofit with rxAndroid, trying to get a response from the server, until server return 0 list size.
getPageAndNext(rows_id), its accept starting point id consider for now its 0 and in next request, I will pass 9th id so that server return after 9th id response.(10th,11th,...15th...19th)
Observable<List<Feed>> getPageAndNext(int id) {
return apiInterface.postGetFeed(membersIds, id)
.flatMap(feedResponse -> {
if (feedResponse.getData().size() > 0) {
return Observable.just(feedResponse.getData())
.concatWith(getPageAndNext(feedResponse.getData().get(feedResponse.getData().size() - 1).getId()));
}
return Observer::onComplete;
});
}
Here per request, I get 10 feeds and insert the feed into room database in onNext method
getPageAndNext(0)
.subscribeOn(Schedulers.computation())
.subscribe(new DisposableObserver<List<Feed>>() {
@Override
public void onNext(List<Feed> feeds) {
//save to room database
memberDatabaseRepository.insertMemberList(feeds);
}
@Override
public void onError(Throwable e) {
Log.e("jjjj", "error"+e);
}
@Override
public void onComplete() {
Log.d("kkkk","done");
}
});
Now I am not getting all response from a server. I am searching for the last 24 hours but I didn't get any solution.
Note: I am able to do 76 API calls after that never getting any response even only 76 APIs call data saved in room database. but there is around 630 API calls
Links :-
How To Do Recursive Observable Call in RxJava?
How to ignore error and continue infinite stream?
RxJava takeUntil with emmision of last item?
How to make multiple requests with reactive android and retrofit