Class: Connection
client.Connection
Client connection to the Temporal Server
⚠️ 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
Raw gRPC access to Temporal Server's Operator service
options
• Readonly
options: ConnectionOptionsWithDefaults
workflowService
• Readonly
workflowService: WorkflowService
Raw gRPC access to Temporal Server's Workflow service
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.
Does not need to be called if you use connect.
This method's result is memoized to ensure it runs only once.
Calls getSystemInfo internally.
Returns
Promise
<void
>
withDeadline
▸ withDeadline<ReturnType
>(deadline
, fn
): Promise
<ReturnType
>
Set the deadline for any service requests executed in fn
's scope.
Type parameters
Name |
---|
ReturnType |
Parameters
Name | Type |
---|---|
deadline | number | Date |
fn | () => Promise <ReturnType > |
Returns
Promise
<ReturnType
>
value returned from fn
withMetadata
▸ withMetadata<ReturnType
>(metadata
, fn
): Promise
<ReturnType
>
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 metadata.
Example
const workflowHandle = await conn.withMetadata({ apiKey: 'secret' }, () =>
conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
);
Type parameters
Name |
---|
ReturnType |
Parameters
Name | Type |
---|---|
metadata | Metadata |
fn | () => Promise <ReturnType > |
Returns
Promise
<ReturnType
>
value returned from 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 by calling ensureConnected.
Parameters
Name | Type |
---|---|
options? | ConnectionOptions |
Returns
Promise
<Connection
>
lazy
▸ Static
lazy(options?
): Connection
Create a lazy Connection
instance.
This method does not verify connectivity with the server. We recommend using connect instead.
Parameters
Name | Type |
---|---|
options? | ConnectionOptions |