Is there an operator or some good approach to achieve doOnEmpty() kind of behaviour with Project Reactor Mono?
I want to have side effects (logging) for operation result.
This is what I have now:
myMono
.map(value -> new Wrapped(value))
.defaultIfEmpty(new Wrapped(null))
.doOnEach( ... )
.flatMap(wrapped ->
wrapped.value == null ?
Mono.empty() : Mono.just(wrapped.value))
So I am wrapping actual value or in case of empty creating empty wrapper. Then the wrapper is consumed for side effects.
Instead using something like doOnEmpty(Consumer> signalConsumer) would be nice. To complicate things a bit more, I need to have access to the Signal in order to access the Context (contains data needed for the logging).
There are these answers but I don't think they apply or provide access to the Context.
So now that I think of this, maybe the proper question is:
"Is there a way to determine on doOnEach(Consumer Signal ) if observable resolved to empty?"