Created
May 22, 2018 10:43
-
-
Save daviddefco/4499e0284471f54f7416ac7603cab037 to your computer and use it in GitHub Desktop.
Reactor Examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of error in processing a flux (with a map) stops the subscription (Only prints 1) | |
Flux.range(1,6) | |
.map(integer -> { | |
if(integer % 2 == 0) { | |
throw new RuntimeException("odd number!"); | |
} else { | |
return integer; | |
} | |
}) | |
.subscribe(flux -> flux.subscribe(System.out::println, System.err::println)); | |
// Example of making Flux discrete and process each element individually. If something fails the rest of | |
// elements are processed too | |
Flux.range(1,6) | |
.flatMap(integer -> { | |
if(integer % 2 == 0) { | |
System.err.println("odd number!"); | |
return Mono.empty(); | |
} else { | |
return Mono.just(integer); | |
} | |
}) | |
.subscribe(System.out::println); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment