Created
August 4, 2021 14:58
-
-
Save cherniag/c87a7584df3738890e0aa14aa183288e to your computer and use it in GitHub Desktop.
split flux into 2
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
public static void main(String[] args) { | |
Flux<Integer> integerFlux = Flux.fromIterable(List.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); | |
Flux<Integer> cache = integerFlux | |
.doOnNext(i -> System.out.println("on next " + i)) | |
.publish() | |
.refCount(2); | |
Flux<Integer> even = cache.filter(i -> i % 2 == 0); | |
Flux<Integer> odd = cache.filter(i -> i % 2 != 0); | |
even.subscribe(i -> System.out.println("on next even " + i), System.err::println, () -> System.out.println("complete even")); | |
odd.subscribe(i -> System.out.println("on next odd " + i), System.err::println, () -> System.out.println("complete odd")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment