Skip to content

Commit 2a3e30b

Browse files
committed
fix: keep stream consumption loop until codegen port
Per @karpetrosyan's review feedback, keeping the stream consumption loop that ensures all events are consumed before the iterator exits. This will remain until the early exit improvement is ported to codegen.
1 parent 4ef87f1 commit 2a3e30b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/anthropic/_streaming.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def __stream__(self) -> Iterator[_T]:
107107

108108
yield process_data(data=data, cast_to=cast_to, response=response)
109109

110+
# Ensure the entire stream is consumed
111+
for _sse in iterator:
112+
pass
113+
110114
def __enter__(self) -> Self:
111115
return self
112116

@@ -214,6 +218,10 @@ async def __stream__(self) -> AsyncIterator[_T]:
214218

215219
yield process_data(data=data, cast_to=cast_to, response=response)
216220

221+
# Ensure the entire stream is consumed
222+
async for _sse in iterator:
223+
pass
224+
217225
async def __aenter__(self) -> Self:
218226
return self
219227

0 commit comments

Comments
 (0)