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>
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.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.bsc.async.AsyncGenerator
AsyncGenerator.Data<E>, AsyncGenerator.Embed<E>, AsyncGenerator.EmbedCompletionHandler, AsyncGenerator.HasResultValue, AsyncGenerator.WithEmbed<E>, AsyncGenerator.WithResult<E> -
Constructor Summary
ConstructorsConstructorDescriptionGeneratorSubscriber(P publisher, BlockingQueue<AsyncGenerator.Data<T>> queue) Constructs a new instance ofGeneratorSubscriber.GeneratorSubscriber(P publisher, Supplier<Object> mapResult, BlockingQueue<AsyncGenerator.Data<T>> queue) Constructs a new instance ofGeneratorSubscriber. -
Method Summary
Modifier and TypeMethodDescriptionnext()Returns the nextData<T>object from this iteration.voidThis method is called when the asynchronous operation is completed successfully.voidHandles an error by queuing it in the delegate's queue with an errored data.voidPasses the received item to the delegated queue as anAsyncGenerator.Dataobject.voidonSubscribe(Flow.Subscription subscription) Handles the subscription event from a Flux.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bsc.async.AsyncGenerator
async, iterator, stream, toCompletableFutureMethods inherited from interface org.bsc.async.AsyncGeneratorOperators
collectAsync, executor, filter, flatMap, forEachAsync, mapMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
GeneratorSubscriber
public GeneratorSubscriber(P publisher, Supplier<Object> mapResult, BlockingQueue<AsyncGenerator.Data<T>> queue) Constructs a new instance ofGeneratorSubscriber.- Type Parameters:
P- the type of the publisher, which must extendFlow.Publisher- Parameters:
mapResult- function that will set generator's resultpublisher- the source publisher that will push data to this subscriberqueue- the blocking queue used for storing asynchronous generator data
-
GeneratorSubscriber
Constructs a new instance ofGeneratorSubscriber.- Type Parameters:
P- the type of the publisher, which must extendFlow.Publisher- Parameters:
publisher- the source publisher that will push data to this subscriberqueue- the blocking queue used for storing asynchronous generator data
-
-
Method Details
-
mapResult
-
onSubscribe
Handles the subscription event from a Flux.This method is called when a subscription to the source
Flowhas been established. The providedFlow.Subscriptioncan be used to manage and control the flow of data emissions.- Specified by:
onSubscribein interfaceFlow.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
Passes the received item to the delegated queue as anAsyncGenerator.Dataobject.- Specified by:
onNextin interfaceFlow.Subscriber<T>- Parameters:
item- The item to be processed and queued.
-
onError
Handles an error by queuing it in the delegate's queue with an errored data.- Specified by:
onErrorin interfaceFlow.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:
onCompletein interfaceFlow.Subscriber<T>
-
next
Returns the nextData<T>object from this iteration.- Specified by:
nextin interfaceAsyncGenerator<T>- Specified by:
nextin interfaceAsyncGeneratorOperators<T>- Returns:
- the next element in the iteration, or null if there is no such element
-