Reactor mapping Mono<Boolean> to Mono<Void>

pixel picture pixel · Dec 23, 2017 · Viewed 14k times · Source

I have function that return Mono<Boolean> and I want to map it to Mono<Void> (since this is something I return in my Controller method).

Is there any better way to return such Mono instead of .flatMap { Mono.empty<Void>() }?

I can't use .map{ null } because mapping function cannot accept nulls.

Answer

Simon Basl&#233; picture Simon Baslé · Dec 24, 2017

yes, simply use booleanMono.then(). it only propagates the terminal signals (onComplete or onError) as a Mono<Void>, ditching the onNext event.