Project Reactor · interview question
Given the following code snippet, what is the expected output order? Flux.just(1, 2, 3).flatMap(i -> Mono.just(i * 2)).subscribe(System.out::println);?
Multiple choiceMediumchapter-19-curatedpremiumproject-reactorfunctional-pipelines-flatmap
Flux.just(1, 2, 3)
.flatMap(i -> Mono.just(i * 2))
.subscribe(System.out::println);Answer and explanation
Correct answer
B. The output order is not guaranteed.
Why
Using flatMap() in a reactive pipeline may result in out-of-order processing due to its asynchronous nature, hence the output order is not guaranteed.
Test yourself on Project Reactor
A free test with instant, explained results. No account needed.
More Project Reactor questions
- In the context of Reactive Streams, what role does a Subscriber play?
- If a Mono completes empty, which of the following methods can be used to provide a default value?
- When transitioning from Spring MVC to WebFlux, what is a key advantage concerning server performance?
- When using Mono<User> in a reactive system, how should you handle a database call to ensure it remains non-blocking?
- What does the Publisher interface in the Reactive Streams specification do?
- Which of the following statements about the Event Loop in a non-blocking reactive system is true?