---
title: "Wait and Stream"
description: "A caller reads a Flow's Stream one message at a time and resumes from the token of the last one. Use it when the caller shows a series of updates, such as progress, instead of waiting for one point."
canonical_url: "https://docs.superdurable.io/design-patterns/responsive-update/wait-and-stream/"
source: "docs/content/design-patterns/responsive-update/stream.mdx"
locale: "en"
language: "python"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# Wait and Stream

Code on this page is in Python. Other languages: [Go](https://docs.superdurable.io/design-patterns/responsive-update/wait-and-stream.go.md) · [Java](https://docs.superdurable.io/design-patterns/responsive-update/wait-and-stream.java.md) · [TypeScript](https://docs.superdurable.io/design-patterns/responsive-update/wait-and-stream.typescript.md) · [Rust](https://docs.superdurable.io/design-patterns/responsive-update/wait-and-stream.rust.md)

A caller reads a Flow's Stream one message at a time and resumes from the token of the last one. Use it when the caller shows a series of updates, such as progress, instead of waiting for one point.

## How it works

The Flow writes messages to a Stream. `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.

In the example, `StreamFlow` writes to a progress Stream. Its read endpoint long-polls for the next message, returns one message, and gives the client the token to keep. The client can issue the next read right after it handles that message.

## Core implementation

The read endpoint takes the caller's token and returns the message with a new resume token. The Go example uses the server's wait cap; the others request up to 20 seconds.

**Python**

```python
@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](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/primitives/stream/controller.py)

## Rules and pitfalls

- **Wait for durable conditions another way.** Stream messages are best effort and are not the Flow result. When the caller needs one durable condition before it proceeds, use [Wait for Step Completion](https://docs.superdurable.io/design-patterns/responsive-update/wait-for-step-completion.md) or [Wait for Attribute Match](https://docs.superdurable.io/design-patterns/responsive-update/wait-for-attribute-match.md).

The [Polling with Long-Running Step Heartbeat](https://docs.superdurable.io/design-patterns/durable-timer/polling-with-long-running-step-heartbeat.md) pattern reports job progress on a Stream that clients read the same way.

## Next

- [Stream](https://docs.superdurable.io/concepts/primitives/stream.md)
- [Client](https://docs.superdurable.io/concepts/application.md#client)
