-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>days</artifactId> | ||
<groupId>com.thegreatapi.100daysofjava</groupId> | ||
<version>1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>day094</artifactId> | ||
|
||
<properties> | ||
<maven.compiler.source>16</maven.compiler.source> | ||
<maven.compiler.target>16</maven.compiler.target> | ||
</properties> | ||
|
||
</project> |
53 changes: 53 additions & 0 deletions
53
days/day094/src/main/java/com/thegreatapi/ahundreddaysofjava/day094/Day094.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.thegreatapi.ahundreddaysofjava.day094; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.Flow; | ||
import java.util.concurrent.SubmissionPublisher; | ||
|
||
public class Day094 { | ||
|
||
public static void main(String[] args) { | ||
List<String> judasPriestMembers = List.of( | ||
"Rob Halford", | ||
"K.K. Downing", | ||
"Glenn Tipton", | ||
"Ian Hill", | ||
"Scott Travis" | ||
); | ||
|
||
var subscriber = new MySubscriber(); | ||
|
||
try (var publisher = new SubmissionPublisher<String>()) { | ||
publisher.subscribe(subscriber); | ||
judasPriestMembers.forEach(publisher::submit); | ||
} | ||
} | ||
|
||
static class MySubscriber implements Flow.Subscriber<String> { | ||
|
||
private Flow.Subscription subscription; | ||
|
||
@Override | ||
public void onSubscribe(Flow.Subscription subscription) { | ||
System.out.println("Started subscription"); | ||
this.subscription = subscription; | ||
subscription.request(1); | ||
} | ||
|
||
@Override | ||
public void onNext(String item) { | ||
System.out.println(item); | ||
subscription.request(1); | ||
} | ||
|
||
@Override | ||
public void onError(Throwable throwable) { | ||
System.err.println("Error: " + throwable); | ||
} | ||
|
||
@Override | ||
public void onComplete() { | ||
System.out.println("Subscription complete"); | ||
} | ||
} | ||
} |
This file contains 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