gpt4 book ai didi

rx-java - flatMapCompletable 不调用给定的 Action

转载 作者:行者123 更新时间:2023-12-03 18:38:10 24 4
gpt4 key购买 nike

我期待 flatMapCompletable 会在 Completable 正常完成时调用给定的 Action。但是,它并不像我想的那样工作。这是一个简单的例子:

    PublishProcessor<String> processor = PublishProcessor.create();

processor.flatMapCompletable(s2 -> {
System.out.println("s2 " + s2);
return Completable.complete();
}).subscribe(() -> {
System.out.println("done"); // it does not come here
});

这是预期的行为吗?如果是这样,我如何检查 Completable 任务是否已完成? Completable.complete().doFinally() ?

最佳答案

您需要调用 processor.onComplete(); 才能获得 Action onComplete。这是因为在它监听传入事件时您仍然订阅了主题。
Flowable 正常完成

    Flowable.just(1).flatMapCompletable(s2 -> {
System.out.println("s2 " + s2);
return Completable.complete();
}).subscribe(() -> {
System.out.println("done"); // it does come here
});

关于rx-java - flatMapCompletable 不调用给定的 Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41471617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com