【发布时间】:2020-09-25 16:51:37
【问题描述】:
我有这两种方法,它们调用异步 API 并在值存在时返回 Mono<Boolean>。为了这个例子,我返回一个随机布尔值,
private Mono<Boolean> checkFirstExists() {
// Replacing actual API call here
return Mono.just(Boolean.FALSE);
}
private Mono<Boolean> checkSecondExists() {
// Replacing actual API call here
return Mono.just(Boolean.TRUE);
}
现在,我有另一个方法应该结合这两种方法的结果,如果 checkFirstExists 或 checkSecondExists 为真,则简单地返回一个布尔值。
private boolean checkIfExists() {
// Should return true if any of the underlying method returns true
final Flux<Boolean> exists = Flux.concat(checkFirstExists(), checkSecondExists());
return exists.blockFirst();
}
这样做的最佳方法是什么? Mono.zip 也许?任何帮助都会很棒。
【问题讨论】: