java.lang.Object
org.bsc.async.AsyncGenerator.Base<E>
- Type Parameters:
E- the type of elements
- All Implemented Interfaces:
AutoCloseable,Iterable<E>,AsyncGenerator<E>
- Direct Known Subclasses:
AsyncGenerator.BaseCancellable
- Enclosing interface:
- AsyncGenerator<E>
public abstract static class AsyncGenerator.Base<E>
extends Object
implements AsyncGenerator<E>, AutoCloseable
Abstract base class for AsyncGenerator implementations.
This class manages an internal ExecutorService for asynchronous operations.
It implements AutoCloseable to ensure proper resource cleanup.
Usage with try-with-resources:
try (AsyncGenerator<String> generator = AsyncGenerator.from(list)) {
generator.forEachAsync(System.out::println);
}
Note: Even if close() is not called explicitly, the internal Cleaner
mechanism will ensure the ExecutorService is properly shutdown when this instance
is garbage collected. However, explicit cleanup via close() or cancel()
is recommended for deterministic resource management.
-
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> -
Method Summary
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.bsc.async.AsyncGenerator
flatMap, forEachAsync, iterator, map, next, reduce, reduceAsync, stream, toCompletableFuture, toCompletableFutureAsyncMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
executor
- Specified by:
executorin interfaceAsyncGenerator<E>
-
close
public void close()Closes this AsyncGenerator and releases its resources.This method shuts down the internal ExecutorService. After calling this method, the generator should not be used for further operations.
This method is idempotent - calling it multiple times has no additional effect.
- Specified by:
closein interfaceAutoCloseable
-
isClosed
public boolean isClosed()Checks if this generator has been closed.- Returns:
trueif the generator has been closed,falseotherwise
-