Skip to content

Commit 7b1bb3b

Browse files
authored
chore: deprecate workflow.stream_events in favor of handler.stream_events (#51)
1 parent f8e6cfd commit 7b1bb3b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/workflows/workflow.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,9 @@ async def stream_events(self) -> AsyncGenerator[Event, None]:
180180
"""
181181
Returns an async generator to consume any event that workflow steps decide to stream.
182182
183+
DEPRECATED: This method is deprecated and will be removed in a future version.
184+
Use `handler.stream_events()` instead, where `handler` is the return value of `workflow.run()`.
185+
183186
To be able to use this generator, the usual pattern is to wrap the `run` call in a background task using
184187
`asyncio.create_task`, then enter a for loop like this:
185188
@@ -190,7 +193,23 @@ async def stream_events(self) -> AsyncGenerator[Event, None]:
190193
print(ev)
191194
192195
await r
196+
197+
New recommended pattern:
198+
wf = StreamingWorkflow()
199+
handler = wf.run()
200+
201+
async for ev in handler.stream_events():
202+
print(ev)
203+
204+
await handler
193205
"""
206+
warnings.warn(
207+
"Workflow.stream_events() is deprecated and will be removed in a future version. "
208+
"Use handler.stream_events() instead, where handler is the return value of workflow.run().",
209+
DeprecationWarning,
210+
stacklevel=2,
211+
)
212+
194213
# In the typical streaming use case, `run()` is not awaited but wrapped in a asyncio.Task. Since we'll be
195214
# consuming events produced by `run()`, we must give its Task the chance to run before entering the dequeueing
196215
# loop.

0 commit comments

Comments
 (0)