我一直在玩retryWhen()方法,我注意到如果您在retryWhen()中使用filter( )并且如果filter()失败,则甚至不会执行回调onCompleted()。你能向我解释为什么会这样吗?提前致谢。
工作案例:
Observable.error(new RuntimeException())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retryWhen(errors -> errors
.filter(throwable -> throwable instanceof RuntimeException)
.zipWith(Observable.range(1, 3), (throwable, retryCount) -> {
Log.i("lol", "retry " + retryCount);
return retryCount;
}))
.subscribe(e -> Log.i("lol", "onNext"), throwable -> Log.i("lol", "onError"), () -> Log.i("lol", "onCompleted"));
工作输出:
I: retry 1
I: retry 2
I: retry 3
I: onCompleted
但是当我用 observable 更改过滤器时,filter(throwable -> throwable instanceof IOException)
就像处于冻结状态一样。没有触发回调。
Observable.error(new RuntimeException())
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.retryWhen(errors -> errors
.filter(throwable -> throwable instanceof IOException)
.zipWith(Observable.range(1, 3), (throwable, retryCount) -> {
Log.i("lol", "retry " + retryCount);
return retryCount;
}))
.subscribe(e -> Log.i("lol", "onNext"), throwable -> Log.i("lol", "onError"), () -> Log.i("lol", "onCompleted"));