【发布时间】:2017-01-25 18:55:47
【问题描述】:
我有一个经过改造的 Observable 调用,它压缩了三个 API 调用 但我想同时进行 3 个调用,但有时其中一个调用失败,但我只有一个主调用,这对我来说是强制性的,其余调用是可选的,因为当其中一个调用失败时,它会出现错误,而我不希望那样,我在想是否有像 JoinObservable.when(OperatorJoinPatterns.or(call1 , call2) .then 但唯一的事情是和
Observable.zip(getSearchObservable(FIRST_PAGE), App.getApi().allbookmarks(), SpotlightUtil.getSpotLightBanner(), App.getApi().getFollowingSuggestions(AppConfigUtil.getFollowingSuggestions().getLimit()),
(searchResult, myFavouritesResults, spotlightListResult, followingSuggestionsResult) -> combineCall(searchResult, myFavouritesResults, spotlightListResult, followingSuggestionsResult, false))
.observeOn(AndroidSchedulers.mainThread())
.doOnNext(spotlightsAndSearchResultAndSuggestionsResult -> {
//my main call that i want if that fail the request should fail
if (!NetUtils.isServerOk(spotlightsAndSearchResultAndSuggestionsResult.getSearchResult().getStatus())) {
throw new ServerErrorException(spotlightsAndSearchResultAndSuggestionsResult.getSearchResult().getErrorMessage());
}
if (spotlightsAndSearchResultAndSuggestionsResult.getSearchResult().posts.size() < PAGE_SIZE) {
rvPosts.setFinished(true);
}
hideLoader();
mPostAdapter.mSuggestions = spotlightsAndSearchResultAndSuggestionsResult.getFollowingSuggestionsResult().getSuggestion();
checkToAddOrRemoveFeedbackSpotLight(spotlightsAndSearchResultAndSuggestionsResult.getSearchResult().posts, true);
})
.doOnError(throwable -> {
ErrorScreenUtils.checkError(throwable, this, true);
hideLoader();
})
.retryWhen(RxActivity.RETRY_CONDITION).compose(bindUntilEvent(FragmentEvent.DESTROY))
.subscribe();
【问题讨论】:
标签: android retrofit rx-java rx-android