0

I have such code:

List<Mono> monoList = foo();
//await when all Monos are finished
try {
    Flux.fromIterable(monoList)
            .flatMap(Function.identity())
            .then()
            .block();

} catch (Exception e) {
    log.warn("error", e);
}

It works perfect when all MONO are finished successfully but doesn't work if at least onee Mono finished with error. Method block throw exceptions and interrupts all other monos. So this code awaits when all mono are finished successfully or when the first error happen.

How to await when all Monos from monoList are finished(doesn't matter succesfully or not)

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

0

This works:

  try {
        Flux.fromIterable(monoList)
                .flatMap(Function.identity())
                .then()
                .onErrorContinue((throwable, o) -> {
                    //just ignore it we've already caught all errors
                })
                .block();

    } catch (Exception e) {
        log.warn("Polling finished with exceptions", e);
    }
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710