java - retryWhen 后未调用 doOnCompleted

标签 java rx-java rx-android

我有这样的东西:

            service.getStuff()
            .map(...)
            .observeOn(AndroidSchedulers.mainThread())
            .retryWhen(errors -> errors.flatMap(t -> {
                return otherObservable.doOnNext(someSideEffect);
            }))
            .doOnCompleted(() ->  onComplete())
            .subscribe(onNext() , onError());

执行onNext(),并在service.getStuff()的原始可观察对象上调用onComplete()

问题:doOnCompleted() 不执行。

原始可观察值(service.getStuff)是:

Observable.create(new Observable.OnSubscribe<InputStream>() {
                                     @Override
                                     public void call(final Subscriber<? super InputStream> subscriber) {
                                         call.enqueue(new Callback() {
                                             @Override
                                             public void onFailure(Call call, IOException e) {
                                                 subscriber.onError(e);
                                             }

                                             @Override
                                             public void onResponse(Call call, Response response) throws IOException {
                                                 subscriber.onNext(response.body().byteStream());
                                                 Log.d("HTTP", "calling complete");
                                                 subscriber.onCompleted();
                                                 Log.d("HTTP", "called complete");
                                             }
                                         });
                                     }
                                 }

最佳答案

我不完全明白发生了什么,但在找到this similar discussion之后我在没有 flatMap 的情况下重新实现了它并且它有效:

.retryWhen(errors -> errors.zipWith(otherObservable, dummyZipFunction));

关于java - retryWhen 后未调用 doOnCompleted,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37093388/

相关文章:

java - 在多个表中执行选择查询后删除重复数据

java - 在旋转排序数组中查找具有重复元素的元素

java - Mockito 使用 ArgumentCaptor 抛出 InvalidUseOfMatchersException

java - mSubscription.unsubscribe onCreate 与 Activity 中的 onDestroy 的工作方式相同吗?

bluetooth-lowenergy - com.polidea.rxandroidble2.exceptions.BleScanException : Scan failed because application registration failed (code 6) Samsung Galaxy 8

android - 用于切换方法的 RxJava Operator

java - 如何通过保存文件布局将不同语言的属性值以其 native 形式写入java中的属性文件?

rx-java - 具有优先级的 RxJava Zip

android - Proguard : can't find referenced method 'android. app.DatePickerDialog 访问$000

android - 用 RxJava 替换监听器