Created
July 17, 2020 04:12
-
-
Save PatrickGopher/2ab86cd11416e0c1285ab51b34326ea8 to your computer and use it in GitHub Desktop.
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) { | |
| CompletableFuture<Void> subTask = null; | |
| try (SubmissionPublisher<Long> pub = new SubmissionPublisher<>()) { | |
| // Create a Subscriber | |
| SimpleSubscriber sub = new SimpleSubscriber("S1", 10); | |
| // Create a processor | |
| FilterProcessor<Long> filter = new FilterProcessor<>(n -> n % 2 == 1); | |
| // Subscribe the filter to the publisher and a subscriber to the filter | |
| pub.subscribe(filter); // publisher add processer | |
| filter.subscribe(sub); // processer add subscriber | |
| LongStream.range(1L, 10).forEach(pub::submit); | |
| } | |
| try { | |
| TimeUnit.SECONDS.sleep(3); | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment