1

我正在尝试运行一个长时间运行的任务,该任务可能对我尝试重试的列表中的某些对象失败,但它重新订阅了整个可观察对象列表。我可以进行嵌套订阅,但这似乎是错误的。有没有比嵌套订阅更好的解决方案?

这是我的实现:

public Observable<ReportItemModel> deferReports() {
        return  Observable.defer(new Callable<ObservableSource<? extends ReportItemModel>>() {
            @Override
            public ObservableSource<? extends ReportItemModel> call() throws Exception {
                return Observable.fromIterable(getReports())
                        .map(new Function<Report, ReportItemModel>() {
                            @Override
                            public ReportItemModel apply(Report report) throws Exception {
                                return report.getReport();
                            }
                        });
            }
        });
}

reportFactory.deferReports()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .retry()
            .subscribe(new Observer<ReportItemModel>() {
                @Override
                public void onSubscribe(Disposable d) {
                }

                @Override
                public void onNext(ReportItemModel value) {
                    Log.d(TAG,value.toString());
                }

                @Override
                public void onError(Throwable e) {
                }

                @Override
                public void onComplete() {
                }
            });
4

0 回答 0