0

我的应用程序中有一个案例,我想从多个来源获取并返回第一个有效数据。我认为 .concatDelayArray() 和 .first() 将是有效的选择,但如果任何非最后一个 Singles 抛出错误,使用它们会导致崩溃。

这是我的测试用例:

Single<String> first = Single.fromCallable(() -> {
    throw new Exception("Random exception");
});
Single<String> second = Single.fromCallable(() -> "");
Single<String> third = Single.fromCallable(() -> "value");

Single.concatArrayDelayError(first, second, third)
    .filter(value -> !value.isEmpty())
    .firstOrError()
    .test()
    .assertValue("value");      

这以崩溃结束:

io.reactivex.rxjava3.exceptions.UndeliverableException: The exception could not be delivered to the consumer because it has already canceled/disposed the flow or the exception has nowhere to go to begin with.

这种情况有更好的运营商吗?

4

0 回答 0