问题
Lets consider following code:
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
I need to await when all mono will be finished.
How could I achieve it?
回答1:
Not mixing different streaming APIs you could utilize side effects instead of subscriptions and await completion with then()
Mono<Void> await = Flux
.fromIterable(apiCall())
.flatMap(m -> m.doOnSuccess(
str -> log.info("Mono is finished with "+ str)
)).then()
来源:https://stackoverflow.com/questions/58914310/how-to-await-when-all-disposable-elements-will-be-finished