Package io.aether.utils.futures
Interface AFuture
-
- All Superinterfaces:
AFutureBase<AFuture>,ToString
public interface AFuture extends AFutureBase<AFuture>
An asynchronous operation that completes with no return value (void). This interface extends the base asynchronous functionality and provides static factory methods (implemented via proxy to AFutureImpl).
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description static AFutureall(AFuture... ff)Returns an AFuture that completes successfully when all futures in the array complete successfully.static AFutureall(java.util.Collection<AFuture> ff)Returns an AFuture that completes successfully when all futures in the collection complete successfully.static AFutureall(java.util.Iterator<AFuture> ff)Returns an AFuture that completes successfully when all futures in the iterator complete successfully.AFutureand(AFuture f)Chains this future with another, creating a new future that completes when both this and the given future complete successfully.static AFutureany(java.lang.Iterable<AFuture> ff)static AFutureany(java.util.Collection<AFuture> ff)Returns an AFuture that completes successfully when any future in the collection completes.static AFutureanyAndCancel(java.util.Collection<AFuture> ff)Returns an AFuture that completes successfully when any future in the collection completes.AFutureapply(ARunnable t)Creates a new AFuture that runs the task upon successful completion of this future.static AFuturecanceled()Creates a cancelled AFuture instance.static AFuturecompleted()voiddone()Marks the future as successfully completed.static AFuturedoThrow(java.lang.Throwable e)static AFuturemake()<T> ARFuture<T>mapRFuture(ASupplier<T> t)Maps the successful completion of this void future to a result-carrying future.<T> ARFuture<T>mapRFutureWithDecomposite(ASupplier<ARFuture<T>> t)static AFutureof()Creates a new AFuture instance that is already successfully completed.static AFutureof(java.lang.Throwable e)Creates an AFuture instance that is already completed with the given Throwable error.static AFuturerun(java.util.concurrent.Executor executor, AConsumer<AFuture> task)Executes a task using the provided executor and completes the returned future when the task is done.static AFuturerun(java.util.concurrent.Executor executor, ARunnable task)Executes a simple runnable task using the provided executor.AFutureto(@NotNull AFuture f)default java.util.concurrent.CompletableFuture<?>toCompletableFuture()booleantryDone()Attempts to mark the future as successfully completed.default booleanwaitDoneSeconds(int seconds)-
Methods inherited from interface io.aether.utils.futures.AFutureBase
addListener, addListener2, cancel, error, getError, getNowRaw, isCanceled, isDone, isError, isFinalStatus, isNotDone, onCancel, onCancel, onError, onError, onError, setError, timeout, timeoutError, timeoutMs, timeoutMs, to, to, tryCancel, tryError, updateStatus
-
-
-
-
Method Detail
-
done
void done()
Marks the future as successfully completed.
-
tryDone
boolean tryDone()
Attempts to mark the future as successfully completed.- Returns:
- true if the status was updated, false otherwise.
-
waitDoneSeconds
default boolean waitDoneSeconds(int seconds)
-
and
AFuture and(AFuture f)
Chains this future with another, creating a new future that completes when both this and the given future complete successfully.- Parameters:
f- The other future to chain with.- Returns:
- A new AFuture that completes when both are done.
-
apply
AFuture apply(ARunnable t)
Creates a new AFuture that runs the task upon successful completion of this future.- Parameters:
t- The runnable task to execute.- Returns:
- A new AFuture that completes after the task is run.
-
mapRFuture
<T> ARFuture<T> mapRFuture(ASupplier<T> t)
Maps the successful completion of this void future to a result-carrying future.- Type Parameters:
T- The type of the result.- Parameters:
t- The supplier to be executed upon completion, providing the result value.- Returns:
- An ARFuture with the result of the supplier.
-
of
static AFuture of()
Creates a new AFuture instance that is already successfully completed.- Returns:
- An immediately completed AFuture.
-
make
static AFuture make()
-
canceled
static AFuture canceled()
Creates a cancelled AFuture instance.- Returns:
- An immediately cancelled AFuture.
-
of
static AFuture of(java.lang.Throwable e)
Creates an AFuture instance that is already completed with the given Throwable error.- Parameters:
e- The exception to complete the future with.- Returns:
- An AFuture completed with an error.
-
run
static AFuture run(java.util.concurrent.Executor executor, AConsumer<AFuture> task)
Executes a task using the provided executor and completes the returned future when the task is done.- Parameters:
executor- The executor to run the task on.task- The task to execute, which can call done()/error() on the future explicitly.- Returns:
- A new AFuture that completes based on the task's execution.
-
run
static AFuture run(java.util.concurrent.Executor executor, ARunnable task)
Executes a simple runnable task using the provided executor.- Parameters:
executor- The executor to run the task on.task- The runnable task to execute.- Returns:
- A new AFuture that completes when the task finishes.
-
anyAndCancel
static AFuture anyAndCancel(java.util.Collection<AFuture> ff)
Returns an AFuture that completes successfully when any future in the collection completes. Cancels all other futures upon completion.- Parameters:
ff- The collection of futures.- Returns:
- A future that completes when the fastest one is done (and cancels others).
-
any
static AFuture any(java.util.Collection<AFuture> ff)
Returns an AFuture that completes successfully when any future in the collection completes.- Parameters:
ff- The collection of futures.- Returns:
- A future that completes when the fastest one is done.
-
all
static AFuture all(AFuture... ff)
Returns an AFuture that completes successfully when all futures in the array complete successfully. Fails or cancels immediately if any individual future fails or cancels.- Parameters:
ff- The array of futures.- Returns:
- A future that completes when all array futures are done.
-
all
static AFuture all(java.util.Iterator<AFuture> ff)
Returns an AFuture that completes successfully when all futures in the iterator complete successfully. Fails or cancels immediately if any individual future fails or cancels.- Parameters:
ff- The iterator of futures.- Returns:
- A future that completes when all iterator futures are done.
-
all
static AFuture all(java.util.Collection<AFuture> ff)
Returns an AFuture that completes successfully when all futures in the collection complete successfully. Fails or cancels immediately if any individual future fails or cancels.- Parameters:
ff- The collection of futures.- Returns:
- A future that completes when all collection futures are done.
-
completed
static AFuture completed()
-
doThrow
static AFuture doThrow(java.lang.Throwable e)
-
toCompletableFuture
default java.util.concurrent.CompletableFuture<?> toCompletableFuture()
-
-