Class GeneratorSubscriber<T>

java.lang.Object
org.bsc.async.internal.reactive.GeneratorSubscriber<T>
Type Parameters:
T - The type of elements produced by this generator.
All Implemented Interfaces:
Iterable<T>, Flow.Subscriber<T>, AsyncGenerator<T>, AsyncGeneratorOperators<T>

public class GeneratorSubscriber<T> extends Object implements Flow.Subscriber<T>, AsyncGenerator<T>
Represents a subscriber for generating asynchronous data streams.

This class implements the Flow.Subscriber and AsyncGenerator interfaces to handle data flow and produce asynchronous data. It is designed to subscribe to a publisher, process incoming items, and manage error and completion signals.

  • Constructor Details

    • GeneratorSubscriber

      public GeneratorSubscriber(P publisher, BlockingQueue<AsyncGenerator.Data<T>> queue)
      Constructs a new instance of GeneratorSubscriber.
      Type Parameters:
      P - the type of the publisher, which must extend Flow.Publisher
      Parameters:
      publisher - the source publisher that will push data to this subscriber
      queue - the blocking queue used for storing asynchronous generator data
  • Method Details

    • onSubscribe

      public void onSubscribe(Flow.Subscription subscription)
      Handles the subscription event from a Flux.

      This method is called when a subscription to the source Flow has been established. The provided Flow.Subscription can be used to manage and control the flow of data emissions.

      Specified by:
      onSubscribe in interface Flow.Subscriber<T>
      Parameters:
      subscription - The subscription object representing this resource owner lifecycle. Used to signal that resources being subscribed to should not be released until this subscription is disposed.
    • onNext

      public void onNext(T item)
      Passes the received item to the delegated queue as an AsyncGenerator.Data object.
      Specified by:
      onNext in interface Flow.Subscriber<T>
      Parameters:
      item - The item to be processed and queued.
    • onError

      public void onError(Throwable error)
      Handles an error by queuing it in the delegate's queue with an errored data.
      Specified by:
      onError in interface Flow.Subscriber<T>
      Parameters:
      error - The Throwable that represents the error to be handled.
    • onComplete

      public void onComplete()
      This method is called when the asynchronous operation is completed successfully. It notifies the delegate that no more data will be provided by adding a done marker to the queue.
      Specified by:
      onComplete in interface Flow.Subscriber<T>
    • next

      public AsyncGenerator.Data<T> next()
      Returns the next Data<T> object from this iteration.
      Specified by:
      next in interface AsyncGenerator<T>
      Specified by:
      next in interface AsyncGeneratorOperators<T>
      Returns:
      the next element in the iteration, or null if there is no such element