In the below code logic, the someFunction()
is called but the mono inside functionThree
never gets executed. Even thought the "Valid" is logged but the returned mono from repository is never executed. Why is that, even though I have subscribed the mono in SomeFunction()?
SomeFunction() {
return functionOne(param).flatMap(param -> functionTwo(param)).then(Boolean.TRUE::toString).subscribe();
}
Mono<Integer> functionOne(int param) {
return Mono.just(param);
}
Mono<List<Integer>> functionTwo(int param) {
return Mono.just(param)
.filter(param -> param != 1)
.switchIfEmpty(functionThree(param));
}
Mono<List<Integer>> functionThree(int param) {
log.info("Valid");
return reactiveStream.findById(param)
.map(obj -> {
log.info("INSIDE STREAM");
return obj.getId;
})
.collectList();
}
param == 1
. - akarnokdfunctionThree
into a deferred source:.switchIfEmpty(Mono.defer(() -> functionThree(param)))
. - akarnokddoOnNext
s all over the place with logging to see where it stops. - akarnokd