Skip to content

Support suspending stream consumers - #164

Merged
joefreeman merged 5 commits into
mainfrom
stream-consumer-suspense
Sep 6, 2026
Merged

Support suspending stream consumers#164
joefreeman merged 5 commits into
mainfrom
stream-consumer-suspense

Conversation

@joefreeman

Copy link
Copy Markdown
Collaborator

This change allows stream consumers to use suspense. If a stream doesn't produce a value within the specified (optional) timeout, the execution suspends, and then gets woken up when a value is available. This also adds an update method to cf.Checkpoint.

Using both together to sum values from a stream:

total = cf.Checkpoint("total", default=0)

@cf.task()
def sum_stream(stream: cf.Stream[int]) -> int:
    with cf.suspense(timeout=1.0):
        for value in stream:
            total.update(lambda x: x + value)
    return total.get()

@joefreeman
joefreeman merged commit 0fd9055 into main Sep 6, 2026
10 checks passed
@joefreeman
joefreeman deleted the stream-consumer-suspense branch September 6, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant