如何等待所有一次性元素何时完成?

问题描述 投票:0回答:1

让我们考虑以下代码:

List<Mono<String>> monoList= apiCall();
List<Disposable> disposableList = monoList.stream()
        .map(m-> m.subscribe(str-> {
                           log.info("Mono is finished with "+ str);
                        })
        ).collect(Collectors.toList());
// I need to await here

我需要等待所有单声道完成。

我该如何实现?

java spring spring-webflux reactor spring-reactive
1个回答
0
投票

不混合使用不同的流式API,您可以利用副作用而不是订阅来使用then()等待完成

© www.soinside.com 2019 - 2024. All rights reserved.