java.lang.Object
org.bsc.async.AsyncGenerator.Base<E>
org.bsc.async.AsyncGenerator.BaseCancellable<E>
org.bsc.async.AsyncGenerator.WithEmbed<E>
- Type Parameters:
E- the type of elements in the generator
- All Implemented Interfaces:
AutoCloseable,Iterable<E>,AsyncGenerator<E>,AsyncGenerator.Cancellable<E>,AsyncGenerator.HasResultValue,AsyncGenerator.IsCancellable
- Enclosing interface:
- AsyncGenerator<E>
public static class AsyncGenerator.WithEmbed<E>
extends AsyncGenerator.BaseCancellable<E>
implements AsyncGenerator.HasResultValue
An asynchronous generator decorator that allows to generators composition embedding other generators.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.bsc.async.AsyncGenerator
AsyncGenerator.Base<E>, AsyncGenerator.BaseCancellable<E>, AsyncGenerator.Cancellable<E>, AsyncGenerator.Data<E>, AsyncGenerator.Embed<E>, AsyncGenerator.EmbedCompletionHandler, AsyncGenerator.HasResultValue, AsyncGenerator.IsCancellable, AsyncGenerator.WithEmbed<E>, AsyncGenerator.WithResult<E> -
Field Summary
Fields inherited from interface org.bsc.async.AsyncGenerator.IsCancellable
CANCELLED -
Constructor Summary
ConstructorsConstructorDescriptionWithEmbed(AsyncGenerator<E> delegate) WithEmbed(AsyncGenerator<E> delegate, AsyncGenerator.EmbedCompletionHandler onGeneratorDoneWithResult) -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean mayInterruptIfRunning) Requests cancellation of the generator.final Executorexecutor()forEachAsync(Consumer<E> consumer) Asynchronously iterates over the elements of the AsyncGenerator and applies the given consumer to each element.iterator()Returns an iterator over the elements of this AsyncGenerator.next()Retrieves the next asynchronous element.<R> CompletableFuture<R>reduce(R result, BiFunction<R, E, R> reducer) <R> CompletableFuture<R>reduceAsync(R result, BiFunction<R, E, R> reducer) Converts the AsyncGenerator to a CompletableFuture.Methods inherited from class org.bsc.async.AsyncGenerator.BaseCancellable
isCancelledMethods inherited from class org.bsc.async.AsyncGenerator.Base
close, isClosedMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bsc.async.AsyncGenerator
flatMap, map, streamMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
WithEmbed
public WithEmbed(AsyncGenerator<E> delegate, AsyncGenerator.EmbedCompletionHandler onGeneratorDoneWithResult) -
WithEmbed
-
-
Method Details
-
executor
- Specified by:
executorin interfaceAsyncGenerator<E>- Overrides:
executorin classAsyncGenerator.Base<E>
-
resultValues
-
resultValue
- Specified by:
resultValuein interfaceAsyncGenerator.HasResultValue
-
next
Description copied from interface:AsyncGeneratorRetrieves the next asynchronous element.- Specified by:
nextin interfaceAsyncGenerator<E>- Returns:
- the next element from the generator
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Description copied from class:AsyncGenerator.BaseCancellableRequests cancellation of the generator.This method sets the cancelled flag and closes the executor to release resources. If
mayInterruptIfRunningistrue, the executor will be shut down immediately, interrupting any running tasks.- Specified by:
cancelin interfaceAsyncGenerator.IsCancellable- Overrides:
cancelin classAsyncGenerator.BaseCancellable<E>- Parameters:
mayInterruptIfRunning- iftrue, interrupt running tasks- Returns:
trueif cancellation was successful,falseif already cancelled
-
iterator
Description copied from interface:AsyncGeneratorReturns an iterator over the elements of this AsyncGenerator. Each call to `next` retrieves the next "resolved" asynchronous element from the generator. -
forEachAsync
Description copied from interface:AsyncGeneratorAsynchronously iterates over the elements of the AsyncGenerator and applies the given consumer to each element.- Specified by:
forEachAsyncin interfaceAsyncGenerator<E>- Parameters:
consumer- the consumer function to be applied to each element- Returns:
- a CompletableFuture representing the completion of the iteration process.
-
reduce
- Specified by:
reducein interfaceAsyncGenerator<E>
-
reduceAsync
- Specified by:
reduceAsyncin interfaceAsyncGenerator<E>
-
toCompletableFuture
Description copied from interface:AsyncGeneratorConverts the AsyncGenerator to a CompletableFuture.- Specified by:
toCompletableFuturein interfaceAsyncGenerator<E>- Returns:
- a CompletableFuture representing the completion of the AsyncGenerator
-
toCompletableFutureAsync
- Specified by:
toCompletableFutureAsyncin interfaceAsyncGenerator<E>
-