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 of CancelableFunction 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 Type
    Method
    Description
    Starts executing the task asynchronously and returns a CompletionStage notified after the computation completes (normally or exceptionally).
  • Method Details

    • executeAsync

      CompletionStage<R> executeAsync(CancellationToken cancelToken)
      Starts executing the task asynchronously and returns a CompletionStage notified after the computation completes (normally or exceptionally).
      Parameters:
      cancelToken - the CancellationToken which 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 an OperationCanceledException exception. This argument cannot be null.
      Returns:
      the CompletionStage representing the completion of the asynchronous computation. This method may never return null.