Here is the piece of code
@Test
public void test_mono_void_mono_empty() {
Mono.just("DATA")
.flatMap(s -> Mono.just(s.concat("-")
.concat(s))
.doOnNext(System.out::println)
.then())
.switchIfEmpty(Mono.just("EMPTY")
.doOnNext(System.out::println)
.then())
.block();
}
that gives the following result to the console:
DATA-DATA
EMPTY
That means that the chain in the first flatMap
was recognized as an empty one.
On the other hand Reactor has the following class MonoEmpty that is returned by a Mono.empty()
method. On top of that, the method says the following:
/**
* Create a {@link Mono} that completes without emitting any item.
*
* <p>
* <img class="marble" src="doc-files/marbles/empty.svg" alt="">
* <p>
* @param <T> the reified {@link Subscriber} type
*
* @return a completed {@link Mono}
*/
public static <T> Mono<T> empty() {
return MonoEmpty.instance();
}
without emitting any item - but I emitted Void
typed object with then()
method.
What is the explanation of that?