Package io.aether.utils.futures
Interface AFutureBase<Self extends AFutureBase<Self>>
-
- Type Parameters:
Self- The concrete future type (AFuture or ARFuture) for fluent chaining.
- All Superinterfaces:
ToString
- All Known Implementing Classes:
ARFutureWithFlag
public interface AFutureBase<Self extends AFutureBase<Self>> extends ToString
Base interface defining the common life cycle, status, and chaining methods for all asynchronous operations (AFuture and ARFuture).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description booleanaddListener(AConsumer<Self> l)Adds a listener to the future's completion status.default SelfaddListener2(AConsumer<Self> l)voidcancel()Cancels the future.Selferror(java.lang.Throwable e)Completes the future with the given error.java.lang.ThrowablegetError()Gets the error Throwable if the future is in an error state.java.lang.ObjectgetNowRaw()Gets the raw result object.booleanisCanceled()Checks if the future has been canceled.booleanisDone()Checks if the future has reached the Done state (completed successfully).booleanisError()Checks if the final status is an error.booleanisFinalStatus()Checks if the future has reached a final state (Done, Error, or Canceled).booleanisNotDone()Checks if the future has not reached the Done state.SelfonCancel(AConsumer<Self> l)Registers a listener to be executed if the future completes with a cancellation.SelfonCancel(ARunnable l)Registers a listener to be executed if the future completes with a cancellation.SelfonError(AFuture l)SelfonError(ARFuture<?> l)SelfonError(AConsumer<java.lang.Throwable> l)Registers a listener to be executed if the future completes with an error.voidsetError(java.lang.Throwable e)Sets the error Throwable.Selftimeout(int seconds, ARunnable task)Sets a timeout duration in seconds, executing a task if the timeout occurs.SelftimeoutError(int seconds, java.lang.String text)Sets a timeout duration in seconds, after which the future is automatically marked as an error.SelftimeoutMs(long ms, AConsumer<Self> task)Sets a timeout duration in milliseconds, executing a consumer with this future if the timeout occurs.SelftimeoutMs(long ms, ARunnable task)Sets a timeout duration in milliseconds, executing a task if the timeout occurs.Selfto(ARunnable t)Executes a runnable task upon successful completion in the current context.Selfto(java.util.concurrent.Executor executor, ARunnable t)Executes a runnable task on the provided executor upon successful completion.SelftryCancel()booleantryError(@NotNull java.lang.Throwable error)booleanupdateStatus(java.lang.Object result)
-
-
-
Method Detail
-
onCancel
Self onCancel(ARunnable l)
Registers a listener to be executed if the future completes with a cancellation.- Parameters:
l- The runnable task to execute on cancellation.
-
updateStatus
boolean updateStatus(java.lang.Object result)
-
onCancel
Self onCancel(AConsumer<Self> l)
Registers a listener to be executed if the future completes with a cancellation.- Parameters:
l- The consumer that accepts the future instance on cancellation.
-
onError
Self onError(AConsumer<java.lang.Throwable> l)
Registers a listener to be executed if the future completes with an error.- Parameters:
l- The consumer that accepts the Throwable error.- Returns:
- This future instance for chaining.
-
isFinalStatus
boolean isFinalStatus()
Checks if the future has reached a final state (Done, Error, or Canceled).- Returns:
- true if the status is final.
-
isError
boolean isError()
Checks if the final status is an error.- Returns:
- true if the future completed with an error.
-
error
Self error(java.lang.Throwable e)
Completes the future with the given error.- Parameters:
e- The Throwable error.- Returns:
- This future instance for chaining.
-
getError
java.lang.Throwable getError()
Gets the error Throwable if the future is in an error state.- Returns:
- The error or null.
-
setError
void setError(java.lang.Throwable e)
Sets the error Throwable. Same aserror(Throwable).- Parameters:
e- The Throwable error.
-
isNotDone
boolean isNotDone()
Checks if the future has not reached the Done state.- Returns:
- true if the future is pending or in an Error/Canceled state.
-
isDone
boolean isDone()
Checks if the future has reached the Done state (completed successfully).- Returns:
- true if completed successfully.
-
isCanceled
boolean isCanceled()
Checks if the future has been canceled.- Returns:
- true if canceled.
-
cancel
void cancel()
Cancels the future.
-
timeoutError
Self timeoutError(int seconds, java.lang.String text)
Sets a timeout duration in seconds, after which the future is automatically marked as an error.- Parameters:
seconds- Timeout duration.text- Error message text.- Returns:
- This future instance for chaining.
-
timeout
Self timeout(int seconds, ARunnable task)
Sets a timeout duration in seconds, executing a task if the timeout occurs.- Parameters:
seconds- Timeout duration.task- The task to run on timeout.- Returns:
- This future instance for chaining.
-
timeoutMs
Self timeoutMs(long ms, ARunnable task)
Sets a timeout duration in milliseconds, executing a task if the timeout occurs.- Parameters:
ms- Timeout duration in milliseconds.task- The task to run on timeout.- Returns:
- This future instance for chaining.
-
timeoutMs
Self timeoutMs(long ms, AConsumer<Self> task)
Sets a timeout duration in milliseconds, executing a consumer with this future if the timeout occurs.- Parameters:
ms- Timeout duration in milliseconds.task- The consumer to run on timeout.- Returns:
- This future instance for chaining.
-
addListener
boolean addListener(AConsumer<Self> l)
Adds a listener to the future's completion status.- Parameters:
l- The consumer that accepts the future instance upon finalization.- Returns:
- true if the listener was successfully added (and the future was not yet finalized).
-
to
Self to(java.util.concurrent.Executor executor, ARunnable t)
Executes a runnable task on the provided executor upon successful completion.- Parameters:
executor- The executor to run the task on.t- The runnable task.- Returns:
- This future instance for chaining.
-
to
Self to(ARunnable t)
Executes a runnable task upon successful completion in the current context.- Parameters:
t- The runnable task.- Returns:
- This future instance for chaining.
-
getNowRaw
java.lang.Object getNowRaw()
Gets the raw result object. Intended for internal implementation use.- Returns:
- The raw result object (which may be NULL, CANCEL_VALUE, or Throwable).
-
tryError
boolean tryError(@NotNull @NotNull java.lang.Throwable error)
-
tryCancel
Self tryCancel()
-
-