Skip to main content

Wait and Stream

Use a Stream when the caller should receive a sequence of updates rather than one readiness boundary. ReadStream waits for the next message after the supplied resume token. The response includes a new token; pass it to the next read to continue in order.

The StreamFlow sample exposes a progress Stream. Its read endpoint long-polls for up to 20 seconds, returns one message, and gives the client the token to keep. A client can issue the next read immediately after handling that message.

Streams are best-effort ordered messages, not a final Flow result. Use WaitForStepCompletion or WaitForAttributeMatch when the caller needs one specific durable condition before it can proceed.

Core implementation

@blueprint.get("/read")
async def read() -> Response:
message = await app_state.client.read_stream(
required_query("workflowId"),
app_state.stream.progress,
optional_query("resumeToken", ""),
timedelta(seconds=20),
)
return jsonify(
value=message.value,
resume_token=message.resume_token,
created_time=message.created_time.isoformat(),
source=message.source,
)

Example: examples/python/dex_examples/primitives/stream/controller.py