Say I have two Monos, one which resolves to Void
/empty and the other producing an Integer
, how can I execute both in parallel, and continue on as a Mono<Integer>
.
Specifically both of these Monos are results of WebClient
requests. Only one of these produces a useful value, but both need to be successful to continue.
eg.
Mono<Void> a = sendSomeData();
Mono<Integer> b = getSomeNumber();
Mono<Integer> resultingStream = runConcurrentAndGetValue(a, b);
How would I write runConcurrentAndGetValue(a,b)
?
Initially I didn't need the value and was using Mono.when(a,b)
and building off of the Mono<Void>
. But now I need the value. I tried using Mono.zip(a,b).map(Tuple2::getT2)
but then learned that zip
will cancel b
because a
has a lower cardinality (0), and will end up with no item as a result.
I could use Mono.when(a).then(b)
but I would really prefer to be able to execute these concurrently. What is the right operator/composition to use in this case?
Edit:
One option I can think of is just a hack to emit an unused value like:
Mono.zip(a.then(Mono.just("placeholder")), b).map(Tuple2::getT2)