java.lang.Object
org.praxislive.code.userapi.Async<T>
- Type Parameters:
T- result type
A lightweight holder for a future value, the result of an asynchronous
operation such as an actor call. An Async can also reflect the failure of
such an operation.
An Async can be explicitly completed, with a value or error. Completion can only happen once.
Async is not thread safe and is not designed for concurrent operation. Use from a single thread, or protect appropriately.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA queue for handling Async instances.static interfaceAsync.Task<T,R> A task intended to be run asynchronously and outside of the main component context. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanComplete the Async with the provided value.booleandone()Whether this Async has been completed, with or without error.error()Get the failure error or null.booleanComplete the Async unsuccessfully with the provided error.booleanfailed()Whether this Async completed with a failure.result()Get the result of this Async if completed without error, otherwise null.
-
Constructor Details
-
Async
public Async()Construct an empty Async.
-
-
Method Details
-
result
Get the result of this Async if completed without error, otherwise null.- Returns:
- result or null
-
error
Get the failure error or null.- Returns:
- error or null
-
done
public boolean done()Whether this Async has been completed, with or without error.- Returns:
- true if done
-
failed
public boolean failed()Whether this Async completed with a failure.- Returns:
- true if failed
-
complete
Complete the Async with the provided value. If this Async is already completed, with or without failure, its state remains the same and this method returns false.- Parameters:
value- value to complete the Async- Returns:
- true if completed
-
fail
Complete the Async unsuccessfully with the provided error. If this Async is already completed, with or without failure, its state remains the same and this method returns false.- Parameters:
error- error to complete the Async- Returns:
- true if completed
-