Class AsyncResult<V>
java.lang.Object
org.springframework.scheduling.annotation.AsyncResult<V>
- Type Parameters:
V
- the value type
- All Implemented Interfaces:
Future<V>
,ListenableFuture<V>
A pass-through
Future
handle that can be used for method signatures
which are declared with a Future
return type for asynchronous execution.
As of Spring 4.1, this class implements ListenableFuture
, not just
plain Future
, along with the corresponding support
in @Async
processing.
As of Spring 4.2, this class also supports passing execution exceptions back to the caller.
- Since:
- 3.0
- Author:
- Juergen Hoeller, Rossen Stoyanchev
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addCallback
(ListenableFutureCallback<? super V> callback) Register the givenListenableFutureCallback
.void
addCallback
(SuccessCallback<? super V> successCallback, FailureCallback failureCallback) Java 8 lambda-friendly alternative with success and failure callbacks.boolean
cancel
(boolean mayInterruptIfRunning) Expose thisListenableFuture
as a JDKCompletableFuture
.static <V> ListenableFuture<V>
Create a new async result which exposes the given exception as anExecutionException
fromFuture.get()
.static <V> ListenableFuture<V>
forValue
(V value) Create a new async result which exposes the given value fromFuture.get()
.get()
boolean
boolean
isDone()
-
Constructor Details
-
AsyncResult
Create a new AsyncResult holder.- Parameters:
value
- the value to pass through
-
-
Method Details
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) -
isCancelled
public boolean isCancelled()- Specified by:
isCancelled
in interfaceFuture<V>
-
isDone
public boolean isDone() -
get
- Specified by:
get
in interfaceFuture<V>
- Throws:
ExecutionException
-
get
- Specified by:
get
in interfaceFuture<V>
- Throws:
ExecutionException
-
addCallback
Description copied from interface:ListenableFuture
Register the givenListenableFutureCallback
.- Specified by:
addCallback
in interfaceListenableFuture<V>
- Parameters:
callback
- the callback to register
-
addCallback
public void addCallback(SuccessCallback<? super V> successCallback, FailureCallback failureCallback) Description copied from interface:ListenableFuture
Java 8 lambda-friendly alternative with success and failure callbacks.- Specified by:
addCallback
in interfaceListenableFuture<V>
- Parameters:
successCallback
- the success callbackfailureCallback
- the failure callback
-
completable
Description copied from interface:ListenableFuture
Expose thisListenableFuture
as a JDKCompletableFuture
.- Specified by:
completable
in interfaceListenableFuture<V>
-
forValue
Create a new async result which exposes the given value fromFuture.get()
.- Parameters:
value
- the value to expose- Since:
- 4.2
- See Also:
-
forExecutionException
Create a new async result which exposes the given exception as anExecutionException
fromFuture.get()
.- Parameters:
ex
- the exception to expose (either an pre-builtExecutionException
or a cause to be wrapped in anExecutionException
)- Since:
- 4.2
- See Also:
-