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.WithEmbed<E>, AsyncGenerator.WithResult<E>
-
Constructor Summary
ConstructorsConstructorDescriptionGeneratorSubscriber
(P publisher, BlockingQueue<AsyncGenerator.Data<T>> queue) Constructs a new instance ofGeneratorSubscriber
. -
Method Summary
Modifier and TypeMethodDescriptionnext()
Returns the nextData<T>
object from this iteration.void
This method is called when the asynchronous operation is completed successfully.void
Handles an error by queuing it in the delegate's queue with an errored data.void
Passes the received item to the delegated queue as anAsyncGenerator.Data
object.void
onSubscribe
(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, wait
Methods inherited from interface org.bsc.async.AsyncGenerator
async, collectAsync, collectAsync, iterator, stream, toCompletableFuture
Methods inherited from interface org.bsc.async.AsyncGeneratorOperators
collectAsync, executor, filter, flatMap, forEachAsync, map
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
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
-
onSubscribe
Handles the subscription event from a Flux.This method is called when a subscription to the source
Flow
has been established. The providedFlow.Subscription
can be used to manage and control the flow of data emissions.- Specified by:
onSubscribe
in 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.Data
object.- Specified by:
onNext
in 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:
onError
in 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:
onComplete
in interfaceFlow.Subscriber<T>
-
next
Returns the nextData<T>
object from this iteration.- Specified by:
next
in interfaceAsyncGenerator<T>
- Specified by:
next
in interfaceAsyncGeneratorOperators<T>
- Returns:
- the next element in the iteration, or null if there is no such element
-