File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change 22# SPDX-License-Identifier: Apache-2.0
33import asyncio
44from asyncio import iscoroutinefunction
5+ from collections import deque
56from collections .abc import AsyncIterable , AsyncIterator , Awaitable , Callable
67from io import BytesIO
78from typing import Any , Self , cast
@@ -297,10 +298,9 @@ def __init__(
297298 Calls to ``write`` will block until the number of chunks is less than this
298299 number. Default is 16.
299300 """
301+ self ._data = deque ()
300302 if intial_data is not None :
301- self ._data = [intial_data ]
302- else :
303- self ._data = []
303+ self ._data .append (intial_data )
304304
305305 if max_buffered_chunks < 1 :
306306 raise ValueError (
@@ -419,7 +419,7 @@ async def __anext__(self) -> bytes:
419419
420420 # Pop the next chunk of data from the buffer, then notify any waiting
421421 # coroutines, returning immediately after.
422- result = self ._data .pop ()
422+ result = self ._data .popleft ()
423423 self ._data_condition .notify ()
424424 return result
425425
Original file line number Diff line number Diff line change @@ -359,12 +359,13 @@ async def test_provider_reads_written_data() -> None:
359359 # Start the read task in the background.
360360 read_task = asyncio .create_task (drain_provider (provider , result ))
361361 await provider .write (b"foo" )
362+ await provider .write (b"bar" )
362363
363364 # Wait for the buffer to drain. At that point all the data should
364365 # be read, but the read task won't actually be complete yet
365366 # because it's still waiting on future data.
366367 await provider .flush ()
367- assert result == [b"foo" ]
368+ assert result == [b"foo" , b"bar" ]
368369 assert not read_task .done ()
369370
370371 # Now actually close the provider, which will let the read task
@@ -373,7 +374,7 @@ async def test_provider_reads_written_data() -> None:
373374 await read_task
374375
375376 # The result should not have changed
376- assert result == [b"foo" ]
377+ assert result == [b"foo" , b"bar" ]
377378
378379
379380async def test_close_stops_writes () -> None :
You can’t perform that action at this time.
0 commit comments