我有这样的事情:

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


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

问题: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 - 重试后不调用doOnCompleted,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37093388/

10-09 09:27