ReactiveX PublishProcessor在onError之后不执行onNext吗?

时间:2018-07-17 19:12:08

标签: android rx-java reactive-programming

我必须使用onError进行分页。因此,我获取了第一组数据,然后关闭了网络并尝试获取另一组数据。 onNext是第一次调用,因为没有网络,因此 // Product pagination private final PublishProcessor<ProductRequest> mPagination; private int mPageNumber; private boolean mIsProductsLoading = false; private final int FETCH_ROW_COUNT = 10; /** * Dagger strictly enforces that arguments not marked with {@code @Nullable} are not injected * with {@code @Nullable} values. */ @Inject ProductPresenter(Intent intent, Service service, SharedPrefsHelper sharedPrefsHelper) { mSubscriptions = new CompositeDisposable(); mPagination = PublishProcessor.create(); } @Override public void fetchProductByType() { if (mProductsView == null) return; mIsProductsLoading = true; mProductsView.startLookUp(); final Disposable disposable = mService.fetchProductByType(mPagination, createProductRequest(), new Service.ResponseCallback() { @Override public void onSuccess(Object response) { mPageNumber = mPageNumber + FETCH_ROW_COUNT; mIsProductsLoading = false; ResultSet<Product> listResult = (ResultSet<Product>) response; // Tell paginator that we got less data than // requested, so no more further calls if (listResult.getData().size() < FETCH_ROW_COUNT) { Logger.logE(ProductPresenter.class.getName(), "onComplete==="); mPagination.onComplete(); } mProductsView.lookUpCompleted(); mProductsView.onRemoteDataReceived(listResult.getData()); } @Override public void onError(NetworkError networkError) { mIsProductsLoading = false; mProductsView.onRemoteDataReceiveFailed(networkError.getAppErrorMessage()); } }); mSubscriptions.add(disposable); } 无法调用,因此当我重新联机时,我将不再能够获取下一组数据。我只是想保持订阅状态。

演讲者班

 public Disposable fetchProductByType(PublishProcessor<ProductRequest> paginate, ProductRequest requestBody, final ResponseCallback callback) {
        final Disposable subscribe = paginate
                .onBackpressureDrop()
                .flatMap(new Function<ProductRequest, Publisher<ResultSet<Product>>>() {
                    @Override
                    public Publisher<ResultSet<Product>> apply(@NonNull ProductRequest page) throws Exception {
                        return networkService.fetchProductByType(page).subscribeOn(Schedulers.io()).onErrorResumeNext(new Function<Throwable, Publisher<? extends ResultSet<Product>>>() {
                            @Override
                            public Publisher<? extends ResultSet<Product>> apply(Throwable throwable) throws Exception {
                                return null;
                            }
                        });
                    }
                }).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<ResultSet<Product>>() {
                    @Override
                    public void accept(ResultSet<Product> productResultSet) throws Exception {
                        callback.onSuccess(productResultSet);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        handleError(callback, throwable);
                    }
                });

        paginate.onNext(requestBody);
        return subscribe;
    }

服务等级

   @POST(RemoteConstants.METHOD_PRODUCT_BY_TYPE)
   Flowable<ResultSet<Product>> fetchProductByType(@Body ProductRequest requestBody);

终点

public class ResultSet<T> extends RemoteStatus {
    private List<T> data;

    private int total;

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }
}

结果集

getData(id: String): Observable<any> {
return this.http.get<any>(`${this.baseUrl}/path/${id}`).pipe(
  concatMap(
    evt =>
      <Observable<any>>(
        this.http
          .get<any>(`${this.baseUrl}/path/relatedby/${evt.child_id}`)
          .pipe(
            map(resp => ({
              evtData: evt,
              childData: resp
            }))
          )
      )
  ),
  retry(3),
  catchError(this.handleError("getData", []))
);

我已阅读this,并尝试实现但无法实现。 Pl。帮我解决这个问题,我被卡住了。

0 个答案:

没有答案