Skip to content

Instantly share code, notes, and snippets.

@PatrickGopher
Created July 17, 2020 04:10
Show Gist options
  • Save PatrickGopher/95617d40ce82ef8ef104c01aa619ffd9 to your computer and use it in GitHub Desktop.
Save PatrickGopher/95617d40ce82ef8ef104c01aa619ffd9 to your computer and use it in GitHub Desktop.
java async Subscriber
public class NormalSubscriber implements Flow.Subscriber<Long> {
private Flow.Subscription subscription;
private String name = "NormalSubscriber";
public NormalSubscriber(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public void onSubscribe(Flow.Subscription subscription) {
this.subscription = subscription;
subscription.request(1);
}
@Override
public void onNext(Long item) {
System.out.printf("odd number: %d", item);
}
@Override
public void onError(Throwable t) {
System.out.printf("err:", t.getMessage());
}
@Override
public void onComplete() {
System.out.printf("odd number check complete");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment