I'm new to Spring WebFlux and do not fully understand the Mono.when()
. The following code does not work as expected:
List<Mono<Void>> results= ....;
String textVar = "my text";
processors.forEach(p -> {
Mono<Object> restResponseMono = client.getSomething();
results.add(restResponseMono.doOnNext(resp -> {
textVar = textVar + resp.getText();
}).then());
});
Mono.when(results).then(
//here it would expect modification of 'textVar'
Mono.just(textVar);
)
After calling the Mono.when(results).then(...)
I would expect all my changes to be applied to the textVar
because in the docu it is written:
[...Aggregate given publishers into a new Mono that will befulfilled when all of the given Publishers have completed....]
And the restResponseMono.then()
should also wait until everything is completed. So I do not know exactly where is my lack of understanding.