Class: NativeConnection
worker.NativeConnection
A Native Connection object that delegates calls to the Rust Core binary extension.
A Worker must use this class to connect to the server.
This class can be used to power @temporalio/client
's Client objects.
Implements
Properties
callContextStorage
• Readonly
callContextStorage: AsyncLocalStorage
<CallContext
>
healthService
• Readonly
healthService: Health
Raw gRPC access to the standard gRPC health service.
operatorService
• Readonly
operatorService: OperatorService
Raw gRPC access to Temporal Server's Operator service
The Operator Service API defines how Temporal SDKs and other clients interact with the Temporal server to perform administrative functions like registering a search attribute or a namespace.
This Service API is NOT compatible with Temporal Cloud. Attempt to use it against a Temporal
Cloud namespace will result in gRPC unauthorized
error.
testService
• Readonly
testService: undefined
| TestService
Raw gRPC access to Temporal Server's Test service
Will be undefined
if connected to a server that does not support the test service.
workflowService
• Readonly
workflowService: WorkflowService
Raw gRPC access to Temporal Server's Workflow service
Implementation of
ConnectionLike.workflowService
Methods
close
▸ close(): Promise
<void
>
Close this connection.
Make sure any Workers using this connection are stopped before calling this method or it will throw an IllegalStateError
Returns
Promise
<void
>
Implementation of
ensureConnected
▸ ensureConnected(): Promise
<void
>
No-op. This class can only be created via eager connection.
Returns
Promise
<void
>
Implementation of
ConnectionLike.ensureConnected
setApiKey
▸ setApiKey(apiKey
): Promise
<void
>
Update the API key for this client. This is only set if metadata
doesn't already have an
"authorization" key.
Use NativeConnectionOptions.apiKey to set the initial metadata for client creation.
Parameters
Name | Type |
---|---|
apiKey | string |
Returns
Promise
<void
>
setMetadata
▸ setMetadata(metadata
): Promise
<void
>
Mapping of gRPC metadata (HTTP headers) to send with each request to the server.
Use NativeConnectionOptions.metadata to set the initial metadata for client creation.
Parameters
Name | Type |
---|---|
metadata | Record <string , string > |
Returns
Promise
<void
>
withAbortSignal
▸ withAbortSignal<ReturnType
>(abortSignal
, fn
): Promise
<ReturnType
>
Set an AbortSignal that, when aborted, cancels any ongoing service requests executed in
fn
's scope. This will locally result in the request call throwing a grpc.ServiceError|ServiceError
with code grpc.status.CANCELLED|CANCELLED; see isGrpcCancelledError.
This method is only a convenience wrapper around NativeConnection.withAbortSignal.
Type parameters
Name |
---|
ReturnType |
Parameters
Name | Type |
---|---|
abortSignal | AbortSignal |
fn | () => Promise <ReturnType > |
Returns
Promise
<ReturnType
>
value returned from fn
Example
const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 10_000);
// 👇 throws if incomplete by the timeout.
await conn.withAbortSignal(ctrl.signal, () => client.workflow.execute(myWorkflow, options));
See
https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
Implementation of
ConnectionLike.withAbortSignal
withDeadline
▸ withDeadline<ReturnType
>(deadline
, fn
): Promise
<ReturnType
>
Set a deadline for any service requests executed in fn
's scope.
The deadline is a point in time after which any pending gRPC request will be considered as failed; this will locally result in the request call throwing a grpc.ServiceError|ServiceError with code grpc.status.DEADLINE_EXCEEDED|DEADLINE_EXCEEDED; see isGrpcDeadlineError.
It is stronly recommended to explicitly set deadlines. If no deadline is set, then it is possible for the client to end up waiting forever for a response.
Type parameters
Name |
---|
ReturnType |
Parameters
Name | Type | Description |
---|---|---|
deadline | number | Date | a point in time after which the request will be considered as failed; either a Date object, or a number of milliseconds since the Unix epoch (UTC). |
fn | () => Promise <ReturnType > | - |
Returns
Promise
<ReturnType
>
the value returned from fn
See
https://grpc.io/docs/guides/deadlines/
Implementation of
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 NativeConnectionOptions.metadata.
Type parameters
Name |
---|
ReturnType |
Parameters
Name | Type |
---|---|
metadata | Metadata |
fn | () => Promise <ReturnType > |
Returns
Promise
<ReturnType
>
value returned from fn
Example
const workflowHandle = await conn.withMetadata({ apiKey: 'secret' }, () =>
conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
);
Implementation of
connect
▸ connect(options?
): Promise
<NativeConnection
>
Eagerly connect to the Temporal server and return a NativeConnection instance
Parameters
Name | Type |
---|---|
options? | NativeConnectionOptions |
Returns
Promise
<NativeConnection
>
create
▸ create(options?
): Promise
<NativeConnection
>
Parameters
Name | Type |
---|---|
options? | NativeConnectionOptions |
Returns
Promise
<NativeConnection
>
Deprecated
use connect
instead