- Type Parameters:
E
- the type of elements. The generator will emitCompletableFutures<E>
elements
- All Superinterfaces:
AsyncGeneratorOperators<E>
,Iterable<E>
- All Known Implementing Classes:
AsyncGenerator.WithEmbed
,AsyncGenerator.WithResult
,AsyncGeneratorQueue.Generator
,GeneratorSubscriber
An asynchronous generator interface that allows generating asynchronous elements.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Represents a data element in the AsyncGenerator.static class
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 TypeMethodDescriptiondefault AsyncGeneratorOperators<E>
async()
return an async generator that use the ForkJoinPool.commonPool() as default executordefault AsyncGeneratorOperators<E>
return an async generator that use the given executorstatic <E,
U> AsyncGenerator<U> collect
(Collection<E> collection, BiConsumer<E, Consumer<CompletableFuture<U>>> consumer) Collects asynchronous elements from a collection.static <E,
U> AsyncGenerator<U> collect
(Iterator<E> iterator, BiConsumer<E, Consumer<CompletableFuture<U>>> consumer) Collects asynchronous elements from an iterator.static <E> AsyncGenerator<E>
empty()
Returns an empty AsyncGenerator.iterator()
Returns an iterator over the elements of this AsyncGenerator.static <E,
U> AsyncGenerator<U> map
(Collection<E> collection, Function<E, CompletableFuture<U>> mapFunction) create a generator, mapping each element to an asynchronous counterpart.static <E,
U> AsyncGenerator<U> map
(Iterator<E> iterator, Function<E, CompletableFuture<U>> mapFunction) create a generator, mapping each element to an asynchronous counterpart.next()
Retrieves the next asynchronous element.stream()
Returns a sequential Stream with the elements of this AsyncGenerator.default CompletableFuture<Object>
Converts the AsyncGenerator to a CompletableFuture.Methods inherited from interface org.bsc.async.AsyncGeneratorOperators
collectAsync, executor, filter, flatMap, forEachAsync, map
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
async
return an async generator that use the given executor- Parameters:
executor
- the executor to use- Returns:
- new async generator
-
async
return an async generator that use the ForkJoinPool.commonPool() as default executor- Returns:
- new async generator
-
next
AsyncGenerator.Data<E> next()Retrieves the next asynchronous element.- Specified by:
next
in interfaceAsyncGeneratorOperators<E>
- Returns:
- the next element from the generator
-
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
-
map
static <E,U> AsyncGenerator<U> map(Iterator<E> iterator, Function<E, CompletableFuture<U>> mapFunction) create a generator, mapping each element to an asynchronous counterpart.- Type Parameters:
E
- the type of elements in the collectionU
- the type of elements in the CompletableFuture- Parameters:
iterator
- the elements iteratormapFunction
- the function to map elements toCompletableFuture
- Returns:
- an AsyncGenerator instance with mapped elements
-
collect
static <E,U> AsyncGenerator<U> collect(Iterator<E> iterator, BiConsumer<E, Consumer<CompletableFuture<U>>> consumer) Collects asynchronous elements from an iterator.- Type Parameters:
E
- the type of elements in the iteratorU
- the type of elements in the CompletableFuture- Parameters:
iterator
- the iterator containing elements to collectconsumer
- the function to consume elements and add them to the accumulator- Returns:
- an AsyncGenerator instance with collected elements
-
map
static <E,U> AsyncGenerator<U> map(Collection<E> collection, Function<E, CompletableFuture<U>> mapFunction) create a generator, mapping each element to an asynchronous counterpart.- Type Parameters:
E
- the type of elements in the collectionU
- the type of elements in the CompletableFuture- Parameters:
collection
- the collection of elements to mapmapFunction
- the function to map elements to CompletableFuture- Returns:
- an AsyncGenerator instance with mapped elements
-
collect
static <E,U> AsyncGenerator<U> collect(Collection<E> collection, BiConsumer<E, Consumer<CompletableFuture<U>>> consumer) Collects asynchronous elements from a collection.- Type Parameters:
E
- the type of elements in the iteratorU
- the type of elements in the CompletableFuture- Parameters:
collection
- the iterator containing elements to collectconsumer
- the function to consume elements and add them to the accumulator- Returns:
- an AsyncGenerator instance with collected elements
-