Skip to main content

Class: Connection

client.Connection

Client connection to the Temporal Service

NOTE: Connections are expensive to construct and should be reused. Make sure to close() any unused connections to avoid leaking resources.

Properties

callContextStorage

Readonly callContextStorage: AsyncLocalStorage<CallContext>


operatorService

Readonly operatorService: OperatorService


options

Readonly options: ConnectionOptionsWithDefaults


workflowService

Readonly workflowService: WorkflowService

Raw gRPC access to the Temporal service.


Client

Static Readonly Client: ServiceClientConstructor

Methods

close

close(): Promise<void>

Close the underlying gRPC client.

Make sure to call this method to ensure proper resource cleanup.

Returns

Promise<void>


ensureConnected

ensureConnected(): Promise<void>

Ensure connection can be established.

This method's result is memoized to ensure it runs only once.

Calls WorkflowService.getSystemInfo internally.

Returns

Promise<void>


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.

The provided metadata is merged on top of any existing metadata in current scope including metadata provided in ConnectionOptions.metadata

example

await conn.withMetadata({ apiKey: 'secret' }, () =>
conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
);

Type parameters

Name
R

Parameters

NameType
metadataMetadata
fn() => Promise<R>

Returns

Promise<R>

returned value of fn


connect

Static connect(options?): Promise<Connection>

Establish a connection with the server and return a Connection instance.

This is the preferred method of creating connections as it verifies connectivity.

Parameters

NameType
options?ConnectionOptions

Returns

Promise<Connection>


lazy

Static lazy(options?): Connection

Create a lazy Connection instance.

This method does not verify connectivity with the server, it is recommended to use connect instead.

Parameters

NameType
options?ConnectionOptions

Returns

Connection