Class SyEventConsumer<T>

java.lang.Object
com.io7m.jsycamore.api.events.SyEventConsumer<T>
Type Parameters:
T - The type of events
All Implemented Interfaces:
Flow.Subscriber<T>

public final class SyEventConsumer<T> extends Object implements Flow.Subscriber<T>
A simple implementation of the Flow.Subscriber interface that exposes a lambda-based API.
  • Method Details

    • subscribe

      public static <T> SyEventConsumer<T> subscribe(Flow.Publisher<T> publisher, Consumer<T> consumer, Runnable onComplete)
      Subscribe to the given publisher, delivering events to consumer (automatically requesting new events each time one is published), and calling onComplete when the publisher is closed.
      Type Parameters:
      T - The type of events
      Parameters:
      publisher - The publisher
      consumer - An event consumer
      onComplete - A function called on closing the publisher
      Returns:
      A consumer
    • subscribe

      public static <T> SyEventConsumer<T> subscribe(Flow.Publisher<T> publisher, Consumer<T> consumer)
      Subscribe to the given publisher, delivering events to consumer (automatically requesting new events each time one is published), and calling onComplete when the publisher is closed.
      Type Parameters:
      T - The type of events
      Parameters:
      publisher - The publisher
      consumer - An event consumer
      Returns:
      A consumer
    • onSubscribe

      public void onSubscribe(Flow.Subscription newSubscription)
      Specified by:
      onSubscribe in interface Flow.Subscriber<T>
    • onNext

      public void onNext(T item)
      Specified by:
      onNext in interface Flow.Subscriber<T>
    • onError

      public void onError(Throwable throwable)
      Specified by:
      onError in interface Flow.Subscriber<T>
    • onComplete

      public void onComplete()
      Specified by:
      onComplete in interface Flow.Subscriber<T>