0

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?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

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()
tynn
  • 38,113
  • 8
  • 108
  • 143