RxJava:将重试与扩展的单一Observable一起使用不会发出数据

时间:2018-08-17 12:00:16

标签: rx-java observable rx-java2

如果将重试运算符添加到通过扩展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

0 个答案:

没有答案