Skip to main content

Class: WorkflowClient

client.WorkflowClient

Client for starting Workflow executions and creating Workflow handles

Constructors

constructor

new WorkflowClient(options?)

Parameters

NameType
options?WorkflowClientOptions

Properties

connection

Readonly connection: ConnectionLike


options

Readonly options: LoadedWorkflowClientOptions

Accessors

workflowService

get workflowService(): WorkflowService

Raw gRPC access to the Temporal service.

NOTE: The namespace provided in options is not automatically set on requests made to the service.

Returns

WorkflowService

Methods

execute

execute<T>(workflowTypeOrFunc, options): Promise<WorkflowResultType<T>>

Starts a new Workflow execution and awaits its completion.

Type parameters

NameType
Textends Workflow

Parameters

NameType
workflowTypeOrFuncstring | T
optionsWorkflowStartOptions<T>

Returns

Promise<WorkflowResultType<T>>

the result of the Workflow execution


getHandle

getHandle<T>(workflowId, runId?, options?): WorkflowHandle<T>

Create a handle to an existing Workflow.

  • If only workflowId is passed, and there are multiple Workflow Executions with that ID, the handle will refer to the most recent one.
  • If workflowId and runId are passed, the handle will refer to the specific Workflow Execution with that Run ID.
  • If workflowId and GetWorkflowHandleOptions.firstExecutionRunId are passed, the handle will refer to the most recent Workflow Execution in the Chain that started with firstExecutionRunId.

A Chain is a series of Workflow Executions that share the same Workflow ID and are connected by:

This method does not validate workflowId. If there is no Workflow Execution with the given workflowId, handle methods like handle.describe() will throw a WorkflowNotFoundError error.

Type parameters

NameType
Textends Workflow

Parameters

NameType
workflowIdstring
runId?string
options?GetWorkflowHandleOptions

Returns

WorkflowHandle<T>


result

result<T>(workflowId, runId?, opts?): Promise<WorkflowResultType<T>>

Gets the result of a Workflow execution.

Follows the chain of execution in case Workflow continues as new, or has a cron schedule or retry policy.

Type parameters

NameType
Textends Workflow

Parameters

NameType
workflowIdstring
runId?string
opts?WorkflowResultOptions

Returns

Promise<WorkflowResultType<T>>


signalWithStart

signalWithStart<T, SA>(workflowTypeOrFunc, options): Promise<WorkflowHandleWithSignaledRunId<T>>

Sends a signal to a running Workflow or starts a new one if not already running and immediately signals it. Useful when you're unsure of the Workflows' run state.

Type parameters

NameType
Textends Workflow
SAextends any[] = []

Parameters

NameType
workflowTypeOrFuncstring | T
optionsWithWorkflowArgs<T, WorkflowSignalWithStartOptions<SA>>

Returns

Promise<WorkflowHandleWithSignaledRunId<T>>

a WorkflowHandle to the started Workflow


start

start<T>(workflowTypeOrFunc, options): Promise<WorkflowHandleWithFirstExecutionRunId<T>>

Start a new Workflow execution.

Type parameters

NameType
Textends Workflow

Parameters

NameType
workflowTypeOrFuncstring | T
optionsWorkflowStartOptions<T>

Returns

Promise<WorkflowHandleWithFirstExecutionRunId<T>>

a WorkflowHandle to the started Workflow


withDeadline

withDeadline<R>(deadline, fn): Promise<R>

Set the deadline for any service requests executed in fn's scope.

Type parameters

Name
R

Parameters

NameType
deadlinenumber | Date
fn() => Promise<R>

Returns

Promise<R>


withMetadata

withMetadata<R>(metadata, fn): Promise<R>

Set metadata for any service requests executed in fn's scope.

see Connection.withMetadata

Type parameters

Name
R

Parameters

NameType
metadataMetadata
fn() => Promise<R>

Returns

Promise<R>

returned value of fn