public final class AwaitResult<T>
extends Object
Represents the outcome of an asynchronous computation that may have succeeded or failed. Returned by Awaitable.allSettled to report each individual task's result without short-circuiting on failure.
An AwaitResult is either a {@linkplain #isSuccess() success}
carrying a value, or a {@linkplain #isFailure() failure} carrying a
Throwable.
This type follows the value object pattern: two instances are {@linkplain #equals(Object) equal} if and only if they have the same success/failure state and carry equal values or errors. Immutability is enforced — all fields are final and no mutating methods are exposed.
Functional composition is supported via map(Function), enabling transformation chains without unwrapping:
AwaitResult<Integer> length = AwaitResult.success("hello").map(String::length)
Inspired by Kotlin's Result, Rust's Result<T, E>,
and C#'s pattern of structured success/error responses.
T - the value type| Type Params | Return Type | Name and description |
|---|---|---|
|
public boolean |
equals(Object o)Compares this result to another object for equality. |
<T> |
public static AwaitResult<T> |
failure(Throwable error)Creates a failure result with the given exception. |
|
public Throwable |
getError()Returns the exception if failed. |
|
public T |
getOrElse(Function<Throwable, ? extends T> fallback)Returns the value if successful, or applies the given function to the error to produce a fallback value. |
|
public T |
getValue()Returns the value if successful. |
|
public int |
hashCode()Returns a hash code consistent with equals(Object). |
|
public boolean |
isFailure()Returns true if this result represents a failed completion. |
|
public boolean |
isSuccess()Returns true if this result represents a successful completion. |
<U> |
public AwaitResult<U> |
map(Function<? super T, ? extends U> fn)Transforms a successful result's value using the given function. |
<T> |
public static AwaitResult<T> |
success(Object value)Creates a successful result with the given value. |
|
public String |
toString()Returns a human-readable representation of this result: AwaitResult.Success[value] or AwaitResult.Failure[error]. |
Compares this result to another object for equality.
Two AwaitResult instances are equal if and only if they
have the same success/failure state and carry
{@linkplain Objects#equals(Object, Object) equal} values or errors.
o - the object to compare withtrue if the given object is an equal AwaitResultCreates a failure result with the given exception.
error is nullerror - the exception that caused the failure; must not be nullT - the value type (never actually used, since the result is a failure)Returns the exception if failed.
Returns the value if successful, or applies the given function to the error to produce a fallback value.
fallback - the function to apply to the error if this result
is a failure; must not be nullReturns the value if successful.
Returns a hash code consistent with equals(Object).
Returns true if this result represents a failed completion.
Returns true if this result represents a successful completion.
Transforms a successful result's value using the given function. If this result is a failure, the error is propagated unchanged.
This is the functor map operation, enabling value
transformation without explicit unwrapping:
AwaitResult<String> name = AwaitResult.success("Groovy")
AwaitResult<Integer> length = name.map(String::length)
assert length.value == 6
fn is nullfn - the mapping function; must not be nullU - the type of the mapped valueCreates a successful result with the given value.
value - the computation result (may be null)T - the value type Returns a human-readable representation of this result:
AwaitResult.Success[value] or AwaitResult.Failure[error].