Interface: WorkflowHandle<T>
client.WorkflowHandle
A client side handle to a single Workflow instance. It can be used to start, signal, query, wait for completion, terminate and cancel a Workflow execution.
Given the following Workflow definition:
export const incrementSignal = defineSignal<[number]>('increment');
export const getValueQuery = defineQuery<number>('getValue');
export const incrementAndGetValueUpdate = defineUpdate<number, [number]>('incrementAndGetValue');
export async function counterWorkflow(initialValue: number): Promise<void>;
Create a handle for running and interacting with a single Workflow:
const client = new WorkflowClient();
// Start the Workflow with initialValue of 2.
const handle = await client.start({
workflowType: counterWorkflow,
args: [2],
taskQueue: 'tutorial',
});
await handle.signal(incrementSignal, 2);
const queryResult = await handle.query(getValueQuery); // 4
const firstUpdateResult = await handle.executeUpdate(incrementAndGetValueUpdate, { args: [2] }); // 6
const secondUpdateHandle = await handle.startUpdate(incrementAndGetValueUpdate, { args: [2] });
const secondUpdateResult = await secondUpdateHandle.result(); // 8
await handle.cancel();
await handle.result(); // throws a WorkflowFailedError with `cause` set to a CancelledFailure.
Type parameters
Name | Type |
---|---|
T | extends Workflow = Workflow |
Hierarchy
-
↳
WorkflowHandle
Properties
client
• Readonly
client: WorkflowClient
Readonly accessor to the underlying WorkflowClient
workflowId
• Readonly
workflowId: string
The workflowId of the current Workflow
Inherited from
Methods
cancel
▸ cancel(): Promise
<IRequestCancelWorkflowExecutionResponse
>
Cancel a running Workflow.
When a Workflow is cancelled, the root scope throws CancelledFailure with message: 'Workflow canceled'
.
That means that all cancellable scopes will throw CancelledFailure
.
Cancellation may be propagated to Activities depending on ActivityOptions#cancellationType, after which
Activity calls may throw an ActivityFailure, and isCancellation(error)
will be true (see isCancellation).
Cancellation may be propagated to Child Workflows depending on ChildWorkflowOptions#cancellationType, after
which calls to executeChild and ChildWorkflowHandle#result will throw, and isCancellation(error)
will be true (see isCancellation).