Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save daviddefco/4499e0284471f54f7416ac7603cab037 to your computer and use it in GitHub Desktop.
Save daviddefco/4499e0284471f54f7416ac7603cab037 to your computer and use it in GitHub Desktop.
Reactor Examples
// 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