Class Task<V>
- java.lang.Object
-
- com.microsoft.durabletask.Task<V>
-
- Type Parameters:
V- the return type of the task
public abstract class Task<V> extends java.lang.ObjectRepresents an asynchronous operation in a durable orchestration.Task<V>instances are created by methods on theTaskOrchestrationContextclass, which is available inTaskOrchestrationimplementations. 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, theawait()method will throw anOrchestratorBlockedException, 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'sawait()method is called, the result will be returned, or aTaskFailedExceptionwill be thrown if the result of the task was an unhandled exception.Note that orchestrator code must never catch
OrchestratorBlockedExceptionbecause doing so can cause the orchestration instance to get permanently stuck.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Vawait()Blocks the orchestrator until this task to complete, and then returns its result.booleanisCancelled()Returnstrueif the task was cancelled.booleanisDone()Returnstrueif completed in any fashion: normally, with an exception, or via cancellation.abstract Task<java.lang.Void>thenAccept(java.util.function.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>thenApply(java.util.function.Function<V,U> fn)Returns a newTaskthat, when this Task completes normally, is executed with this Task's result as the argument to the supplied function.
-
-
-
Method Detail
-
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
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(java.util.function.Function<V,U> fn)
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
public abstract Task<java.lang.Void> thenAccept(java.util.function.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.- Parameters:
fn- the function to use to compute the value of the returned Task- Returns:
- the new Task
-
-