- Type Parameters:
E
- the type of elements. The generator will emitCompletableFutures<E>
elements
- All Superinterfaces:
Iterable<E>
- All Known Subinterfaces:
AsyncGenerator.Cancellable<E>
- All Known Implementing Classes:
AsyncGenerator.Base
,AsyncGenerator.BaseCancellable
,AsyncGenerator.WithEmbed
,AsyncGenerator.WithResult
,AsyncGeneratorQueue.Generator
,GeneratorSubscriber
An asynchronous generator interface that allows generating asynchronous elements.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
static class
static interface
static final record
Represents a data element in the AsyncGenerator.static class
static interface
static interface
static interface
static class
An asynchronous generator decorator that allows to generators composition embedding other generators.static class
An asynchronous generator decorator that allows retrieving the result value of the asynchronous operation, if any. -
Method Summary
Modifier and TypeMethodDescriptionstatic <E> AsyncGenerator<E>
empty()
Returns an empty AsyncGenerator.executor()
default <U> AsyncGenerator<U>
flatMap
(Function<E, CompletableFuture<U>> mapFunction) Maps the elements of this generator to a new asynchronous generator, and flattens the resulting nested generators.default CompletableFuture<Object>
forEachAsync
(Consumer<E> consumer) Asynchronously iterates over the elements of the AsyncGenerator and applies the given consumer to each element.static <E> AsyncGenerator<E>
Collects asynchronous elements from an iterator.iterator()
Returns an iterator over the elements of this AsyncGenerator.default <U> AsyncGenerator<U>
Maps the elements of this generator to a new asynchronous generator.next()
Retrieves the next asynchronous element.default <R> CompletableFuture<R>
reduce
(R result, BiFunction<R, E, R> reducer) default <R> CompletableFuture<R>
reduceAsync
(R result, BiFunction<R, E, R> reducer) resultValue
(Iterator<?> iterator) resultValue
(AsyncGenerator<?> generator) stream()
Returns a sequential Stream with the elements of this AsyncGenerator.default CompletableFuture<Object>
Converts the AsyncGenerator to a CompletableFuture.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
resultValue
-
resultValue
-
next
AsyncGenerator.Data<E> next()Retrieves the next asynchronous element.- Returns:
- the next element from the generator
-
executor
Executor executor() -
map
Maps the elements of this generator to a new asynchronous generator.- Type Parameters:
U
- the type of elements in the new generator- Parameters:
mapFunction
- the function to map elements to a new asynchronous counterpart- Returns:
- a generator with mapped elements
-
flatMap
Maps the elements of this generator to a new asynchronous generator, and flattens the resulting nested generators.- Type Parameters:
U
- the type of elements in the new generator- Parameters:
mapFunction
- the function to map elements to a new asynchronous counterpart- Returns:
- a generator with mapped and flattened elements
-
forEachAsync
Asynchronously iterates over the elements of the AsyncGenerator and applies the given consumer to each element.- Parameters:
consumer
- the consumer function to be applied to each element- Returns:
- a CompletableFuture representing the completion of the iteration process.
-
reduce
-
reduceAsync
-
toCompletableFuture
Converts the AsyncGenerator to a CompletableFuture.- Returns:
- a CompletableFuture representing the completion of the AsyncGenerator
-
stream
Returns a sequential Stream with the elements of this AsyncGenerator. Each CompletableFuture is resolved and then make available to the stream.- Returns:
- a Stream of elements from the AsyncGenerator
-
iterator
Returns an iterator over the elements of this AsyncGenerator. Each call to `next` retrieves the next "resolved" asynchronous element from the generator. -
empty
Returns an empty AsyncGenerator.- Type Parameters:
E
- the type of elements- Returns:
- an empty AsyncGenerator
-
from
Collects asynchronous elements from an iterator.- Type Parameters:
E
- the type of elements in the iterator- Parameters:
iterator
- the iterator containing elements to collect- Returns:
- an AsyncGenerator instance with collected elements
-