Class: WorkflowStream
workflowStreams.WorkflowStream
Workflow-side stream object — append-only log with publish/poll handlers.
Construct once at the start of your workflow function; the constructor registers the workflow stream signal, update, and query handlers on the current workflow.
Registered handlers:
__temporal_workflow_stream_publishsignal — external publish with dedup__temporal_workflow_stream_pollupdate — long-poll subscription__temporal_workflow_stream_offsetquery — current log length
For continue-as-new, thread a WorkflowStreamState | undefined field through
the workflow input and pass it as priorState.
Constructors
constructor
• new WorkflowStream(priorState?): WorkflowStream
Parameters
| Name | Type |
|---|---|
priorState? | WorkflowStreamState |
Returns
Methods
continueAsNew
▸ continueAsNew<F>(buildArgs, options?): Promise<never>
Drain, wait for in-flight handlers, then continueAsNew with built args.
Replaces the recipe detachPollers() → condition(allHandlersFinished) →
continueAsNew(...) for the common case where the only thing that
varies across CAN boundaries is the workflow's own arguments.
buildArgs is invoked after pollers detach, with the resulting
WorkflowStreamState as its single argument, and must return the positional
argument tuple for the new run.
Type parameters
| Name | Type |
|---|---|
F | extends Workflow |
Parameters
| Name | Type | Description |
|---|---|---|
buildArgs | (state: WorkflowStreamState) => Parameters<F> | Receives the post-detach workflow stream state and returns the positional args for the new run. |
options? | Object | - |
options.publisherTtl? | Duration | Forwarded to getState. Does not return; continueAsNew rejects with an internal exception that the SDK uses to close the run. |
Returns
Promise<never>
Example
await stream.continueAsNew<typeof myWorkflow>((state) => [{
itemsProcessed,
streamState: state,
}]);
detachPollers
▸ detachPollers(): void
Unblock all waiting poll handlers and reject new polls for CAN.
Returns
void
getState
▸ getState(publisherTtl?): WorkflowStreamState
Return a serializable snapshot of workflow stream state for continue-as-new.
Prunes publisher dedup entries older than publisherTtl. Defaults
to 15 minutes.
Parameters
| Name | Type |
|---|---|
publisherTtl? | Duration |
Returns
topic
▸ topic<T>(name): WorkflowTopicHandle<T>
Get a typed handle for publishing to 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
truncate
▸ truncate(upToOffset): void
Discard log entries before upToOffset. After truncation, polls requesting an offset before the new base will receive an error.
Raises ApplicationFailure with type 'TruncateOutOfRange' and
nonRetryable: true when the requested offset is past the end of
the log. Mirrors how onPoll reports 'TruncatedOffset': an update
handler invoking truncate surfaces the error to the caller without
failing the workflow task.
Parameters
| Name | Type |
|---|---|
upToOffset | number |
Returns
void