File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments