Package org.jtrim2.concurrent
Interface AsyncFunction<R>
- Type Parameters:
R- the type of the result of the asynchronous computation
public interface AsyncFunction<R>
Represents an asynchronous computation. Note that although, instances of this interface represent
an asynchronous computation, they are not strictly required to execute the computation asynchronously.
That is, callers must be aware, that the computation might have been done synchronously on the calling
thread.
If you have a synchronous task, you can convert it using the jtrim-executor module with
CancelableTasks.toAsync
Thread safety
The thread-safety property ofCancelableFunction is completely
implementation dependent, so in general they does not need to be thread-safe.
Synchronization transparency
AsyncFunction is not required to be synchronization transparent.-
Method Summary
Modifier and TypeMethodDescriptionexecuteAsync(CancellationToken cancelToken) Starts executing the task asynchronously and returns aCompletionStagenotified after the computation completes (normally or exceptionally).
-
Method Details
-
executeAsync
Starts executing the task asynchronously and returns aCompletionStagenotified after the computation completes (normally or exceptionally).- Parameters:
cancelToken- theCancellationTokenwhich can signal that the asynchronous computation is to be canceled. The computation may ignore this request. However, if it does not, it must complete exceptionally with anOperationCanceledExceptionexception. This argument cannot benull.- Returns:
- the
CompletionStagerepresenting the completion of the asynchronous computation. This method may never returnnull.
-