0
我一直在retryWhen()方法玩弄,我注意到,如果你使用过滤器()内retryWhen()如果过滤器()失败有没有回调甚至不执行onCompleted()。你能向我解释为什么会发生这种情况?提前致谢。RxJava2使用retryWhen与过滤
的工作情况:
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
但是当我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"));
感谢您的info.Yeah我使用'if'语句,但只是想尝试,如果它也与'filter()'一起工作。虽然我期望在这种情况下至少调用“onCompleted()”方法。 – santalu
同样,由于运营商没有收到任何回应,它不会做任何事情。除非源完成,否则提供给函数的observable将不会完成。 –