Skip to content

Instantly share code, notes, and snippets.

@PatrickGopher
Created July 17, 2020 04:12
Show Gist options
  • Select an option

  • Save PatrickGopher/2ab86cd11416e0c1285ab51b34326ea8 to your computer and use it in GitHub Desktop.

Select an option

Save PatrickGopher/2ab86cd11416e0c1285ab51b34326ea8 to your computer and use it in GitHub Desktop.
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