Skip to main content

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_publish signal — external publish with dedup
  • __temporal_workflow_stream_poll update — long-poll subscription
  • __temporal_workflow_stream_offset query — 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

NameType
priorState?WorkflowStreamState

Returns

WorkflowStream

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

NameType
Fextends Workflow

Parameters

NameTypeDescription
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?DurationForwarded 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

NameType
publisherTtl?Duration

Returns

WorkflowStreamState


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

NameType
Tunknown

Parameters

NameType
namestring

Returns

WorkflowTopicHandle<T>


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

NameType
upToOffsetnumber

Returns

void