Class: WorkflowStreamClient
workflowStreamsClient.WorkflowStreamClient
Constructors
constructor
• new WorkflowStreamClient(handle, options?): WorkflowStreamClient
Parameters
| Name | Type |
|---|---|
handle | WorkflowHandle<Workflow> |
options? | WorkflowStreamClientOptions |
Returns
Methods
[asyncDispose]
▸ [asyncDispose](): Promise<void>
Dispose pattern: stop the flusher and drain remaining items.
Use via await using client = WorkflowStreamClient.create(...) so the
scope exit guarantees a final drain. For tests or call sites that
cannot use await using, invoke this method directly:
await client[Symbol.asyncDispose]().
Returns
Promise<void>
flush
▸ flush(): Promise<void>
Flush buffered (and pending) items and wait for server confirmation.
Returns once the items buffered at call time have been signaled to the workflow and acknowledged by the server. Returns immediately if there is nothing to send.
In addition to the declarative forceFlush=true on publish
and to the automatic flush on [Symbol.asyncDispose], use
this when the caller needs proof that prior publications reached
the server at a moment that does not naturally correspond to a
specific event.
Safe to call concurrently with publish() and with the background
flusher: the in-flight serialization on flushOnce makes signal
sends sequential. Items added concurrently after entry may
piggyback on this flush or be deferred to a subsequent one.
Throws FlushTimeoutError if a pending batch cannot be sent
within maxRetryDuration. Also surfaces any deferred timeout from a
prior background flusher failure: without that, flush() could
return success against an empty buffer while an earlier batch had
already been dropped, hiding data loss.
Returns
Promise<void>
getOffset
▸ getOffset(): Promise<number>
Query the current global offset.
Returns
Promise<number>
subscribe
▸ subscribe(topics?, fromOffset?, options?): AsyncGenerator<WorkflowStreamItem<IPayload>, void, unknown>
Async generator that polls for new items.
Default — yields items with data: Payload (no decode). Use a payload
converter such as defaultPayloadConverter.fromPayload<T>(item.data)
to decode at the call site.
With resultType: true — each item is decoded via the client's
configured payload converter and yielded as the generic T.
Automatically follows continue-as-new chains when created via WorkflowStreamClient.create.
Parameters
| Name | Type | Description |
|---|---|---|
topics? | string | string[] | Topic filter. A single topic name, an array of topic names, or undefined. Undefined or an empty array means all topics. |
fromOffset? | number | - |
options? | SubscribeOptions | - |
Returns
AsyncGenerator<WorkflowStreamItem<IPayload>, void, unknown>
▸ subscribe<T>(topics, fromOffset, options): AsyncGenerator<WorkflowStreamItem<T>, void, unknown>
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
topics | undefined | string | string[] |
fromOffset | number |
options | SubscribeOptions & { resultType: true } |
Returns
AsyncGenerator<WorkflowStreamItem<T>, void, unknown>
topic
▸ topic<T>(name): TopicHandle<T>
Get a typed handle for publishing to and subscribing from name.
Repeated calls with the same name return the same handle instance.
The type parameter T is purely a compile-time annotation — see
the module note in TopicHandle for the difference from
sdk-python's runtime type-uniformity check.
Type parameters
| Name | Type |
|---|---|
T | unknown |
Parameters
| Name | Type |
|---|---|
name | string |
Returns
TopicHandle<T>
create
▸ create(client, workflowId, options?): WorkflowStreamClient
Create a WorkflowStreamClient from an explicit Temporal client and workflow ID.
Use this when the caller has an explicit Client and workflowId in
hand (starters, BFFs, other workflows' activities). For code running
inside an activity that targets its own parent workflow, use
WorkflowStreamClient.fromWithinActivity.
A client created through this method follows continue-as-new chains in
subscribe() and uses the client's payload converter for per-item
Payload construction.
Parameters
| Name | Type |
|---|---|
client | Client |
workflowId | string |
options? | WorkflowStreamClientOptions |
Returns
fromWithinActivity
▸ fromWithinActivity(options?): WorkflowStreamClient
Create a WorkflowStreamClient targeting the current activity's parent workflow.
Must be called from within an activity. The Temporal client and parent workflow id are taken from the activity context.
Parameters
| Name | Type |
|---|---|
options? | WorkflowStreamClientOptions |