如果将重试运算符添加到通过扩展subscriber
创建的observable
中,则Single
不会接收到数据。
getSingle()
.retry(1)
.subscribe(System.out::println, System.out::println);
getSingleExt()
.subscribe(res -> System.out.println("WITHOUT RETRY " + res),
System.out::println);
getSingleExt()
.retry(1)
.subscribe(res -> System.out.println("WITH RETRY " + res),
System.out::println);
private static Single<String> getSingle() {
return Single.create(emitter -> emitter.onSuccess("Single.create"));
}
private static Single<String> getSingleExt() {
return new ExtendedSingle();
}
private static class ExtendedSingle extends Single<String> {
@Override
protected void subscribeActual(SingleObserver<? super String> emitter) {
emitter.onSuccess("ExtendedSingle");
}
}
输出
Single.create
WITHOUT RETRY ExtendedSingle
预期
Single.create
WITHOUT RETRY ExtendedSingle
WITH RETRY ExtendedSingle