I want to have a Mono
that calls another async method that returns an Optional
type to:
- have a value if the
Optional
is not empty, - is
MonoEmpty
if theOptional
value is empty.
Here's what I do right now:
Mono.fromCallable(() -> someApi.asyncCall())
.filter(Optional::isPresent)
.map(Optional::get)
Obviously, this is not ideal since it uses two operators after the callable completed. If possible, I'd like to have the Mono.empty()
or mono value from inside fromCallable
.
What is the best way to achieve what I want?
Mono.fromCallable(() -> someApi.asyncCall()).flatMap(Mono::justOrEmpty)
– Agriculturist