Class Task<V>
- Type Parameters:
V- the return type of the task
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 TypeMethodDescriptionabstract Vawait()Blocks the orchestrator until this task to complete, and then returns its result.booleanReturnstrueif the task was cancelled.booleanisDone()Returnstrueif completed in any fashion: normally, with an exception, or via cancellation.thenAccept(Consumer<V> fn) Returns a newTaskthat, 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 newTaskthat, when this Task completes normally, is executed with this Task's result as the argument to the supplied function.
-
Method Details
-
isDone
public boolean isDone()Returnstrueif completed in any fashion: normally, with an exception, or via cancellation.- Returns:
trueif completed, otherwisefalse
-
isCancelled
public boolean isCancelled()Returnstrueif the task was cancelled.- Returns:
trueif the task was cancelled, otherwisefalse
-
await
Blocks the orchestrator until this task to complete, and then returns its result.- Returns:
- the result of the task
-
thenApply
Returns a newTaskthat, 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
Returns a newTaskthat, 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
-