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('increment');
export const getValueQuery = defineQuery<number>('getValue');
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);
await handle.query(getValueQuery); // 4
await handle.cancel();
await handle.result(); // throws WorkflowExecutionCancelledError
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).
Returns
Promise
<IRequestCancelWorkflowExecutionResponse
>
describe
▸ describe(): Promise
<WorkflowExecutionDescription
>
Describe the current workflow execution
Returns
Promise
<WorkflowExecutionDescription
>
fetchHistory
▸ fetchHistory(): Promise
<IHistory
>
Return a workflow execution's history
Returns
Promise
<IHistory
>
query
▸ query<Ret
, Args
>(def
, ...args
): Promise
<Ret
>
Query a running or completed Workflow.
Example
await handle.query(getValueQuery);
await handle.query<number, []>('getValue');
Type parameters
Name | Type |
---|---|
Ret | Ret |
Args | extends any [] = [] |
Parameters
Name | Type | Description |
---|---|---|
def | string | QueryDefinition <Ret , Args , string > | a query definition as returned from defineQuery or query name (string) |
...args | Args | - |
Returns
Promise
<Ret
>
result
▸ result(): Promise
<WorkflowResultType
<T
>>
Promise that resolves when Workflow execution completes
Returns
Promise
<WorkflowResultType
<T
>>
Inherited from
signal
▸ signal<Args
, Name
>(def
, ...args
): Promise
<void
>
Signal a running Workflow.
Example
await handle.signal(incrementSignal, 3);
Type parameters
Name | Type |
---|---|
Args | extends any [] = [] |
Name | extends string = string |
Parameters
Name | Type | Description |
---|---|---|
def | string | SignalDefinition <Args , Name > | a signal definition as returned from defineSignal |
...args | Args | - |
Returns
Promise
<void
>
Inherited from
terminate
▸ terminate(reason?
): Promise
<ITerminateWorkflowExecutionResponse
>
Terminate a running Workflow
Parameters
Name | Type |
---|---|
reason? | string |
Returns
Promise
<ITerminateWorkflowExecutionResponse
>