Observable<Integer> call = Observable.create(emitter -> {
emitter.onNext(1);
emitter.onError(new Throwable("Error"));
});
call
.retryWhen(throwableObservable -> throwableObservable)
.subscribe(integer -> System.out.println(integer), throwable -> System.out.println(throwable.getMessage()));
此代码按预期工作(不断打印“1”),但如果我将其更改为:
.retryWhen(throwableObservable -> throwableObservable.delay(1, TimeUnit.SECONDS))
它只会打印一次'1'并且不会重试。