Is there any operator on Mono that would allow me to log fact that mono was empty?
I cannot use hasElement() because I need result and I don't want to introduce hacky solutions like abusing switchIfEmpty
You could use doOnSuccess and test if data is null
.doOnSuccess(data -> {
if (data == null) {
//onEmpty behavior
}
})
The issue that the OP is describing is missing functionality in the module (imo). Whether you do:
.switchIfEmpty(
Mono.defer(() -> {
//onEmpty behavior
return Mono.empty();
})
)
or what the accepted answer is:
.doOnSuccess(data -> {
if (data == null) {
//onEmpty behavior
}
})
(.doOnEach is similar to .doOnSuccess, except it also fires on error signals)
Neither method name really describes the purpose of the code block, which is to only fire on an empty signal. It makes it more time consuming to browse code when debugging issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With