Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reactor mapping Mono<Boolean> to Mono<Void>

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.

like image 978
pixel Avatar asked Dec 23 '17 19:12

pixel


People also ask

How do you convert flux to Mono?

Instead of take(1) , you could use next() . This will transform the Flux into a valued Mono by taking the first emitted item, or an empty Mono if the Flux is empty itself.

What is flatMapMany?

flatMap. flatMapMany. Java Streams. Accepts Function SE -> SE which takes a synchronous element and returns a single synchronous element. Returns a Java Stream.

Do something if Mono is empty?

Default value if mono is empty. If you want to provide a default value when the mono is completed without any data, then use defaultIfEmpty method. For example, the following code tries to fetch the customer data from the database by using the customer id .


1 Answers

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

like image 136
Simon Baslé Avatar answered Oct 27 '22 17:10

Simon Baslé