Class Task<V>

java.lang.Object
io.dapr.durabletask.Task<V>
Type Parameters:
V - the return type of the task

public abstract class Task<V> extends Object
Represents an asynchronous operation in a durable orchestration.

Task<V> instances are created by methods on the TaskOrchestrationContext class, which is available in TaskOrchestration implementations. For example, scheduling an activity will return a task.

 Task<int> activityTask = ctx.callActivity("MyActivity", someInput, int.class);
 

Orchestrator code uses the await() method to block on the completion of the task and retrieve the result. If the task is not yet complete, the await() method will throw an OrchestratorBlockedException, which pauses the orchestrator's execution so that it can save its progress into durable storage and schedule any outstanding work. When the task is complete, the orchestrator will run again from the beginning and the next time the task's await() method is called, the result will be returned, or a TaskFailedException will be thrown if the result of the task was an unhandled exception.

Note that orchestrator code must never catch OrchestratorBlockedException because doing so can cause the orchestration instance to get permanently stuck.

  • Method Summary

    Modifier and Type
    Method
    Description
    abstract V
    Blocks the orchestrator until this task to complete, and then returns its result.
    boolean
    Returns true if the task was cancelled.
    boolean
    Returns true if completed in any fashion: normally, with an exception, or via cancellation.
    abstract Task<Void>
    Returns a new Task that, when this Task completes normally, is executed with this Task's result as the argument to the supplied action.
    abstract <U> Task<U>
    Returns a new Task that, when this Task completes normally, is executed with this Task's result as the argument to the supplied function.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • isDone

      public boolean isDone()
      Returns true if completed in any fashion: normally, with an exception, or via cancellation.
      Returns:
      true if completed, otherwise false
    • isCancelled

      public boolean isCancelled()
      Returns true if the task was cancelled.
      Returns:
      true if the task was cancelled, otherwise false
    • await

      public abstract V await()
      Blocks the orchestrator until this task to complete, and then returns its result.
      Returns:
      the result of the task
    • thenApply

      public abstract <U> Task<U> thenApply(Function<V,U> fn)
      Returns a new Task that, when this Task completes normally, is executed with this Task's result as the argument to the supplied function.
      Type Parameters:
      U - the function's return type
      Parameters:
      fn - the function to use to compute the value of the returned Task
      Returns:
      the new Task
    • thenAccept

      public abstract Task<Void> thenAccept(Consumer<V> fn)
      Returns a new Task that, when this Task completes normally, is executed with this Task's result as the argument to the supplied action.
      Parameters:
      fn - the function to use to compute the value of the returned Task
      Returns:
      the new Task