From f7ea01155f88e341b4256e470b694ebd0c372fe8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 30 Sep 2024 12:25:52 -0500 Subject: [PATCH] avoid consuming iterable --- src/aiohappyeyeballs/_staggered.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/aiohappyeyeballs/_staggered.py b/src/aiohappyeyeballs/_staggered.py index e20d2f6..870327f 100644 --- a/src/aiohappyeyeballs/_staggered.py +++ b/src/aiohappyeyeballs/_staggered.py @@ -126,7 +126,6 @@ async def run_one_coro( start_next_timer: Optional[asyncio.TimerHandle] = None start_next: Optional[asyncio.Future[None]] task: asyncio.Task[Optional[Tuple[_T, int]]] - waiters: Iterable[asyncio.Future[Any]] done: Union[asyncio.Future[None], asyncio.Task[Optional[Tuple[_T, int]]]] coro_iter = iter(coro_fns) this_index = -1 @@ -149,16 +148,17 @@ async def run_one_coro( break while tasks: - waiters = [*tasks, start_next] if start_next else tasks - done = await _wait_one(waiters, loop) - - if done is start_next: - # The current task has failed or the timer has expired - # so we need to start the next task. - if start_next_timer: - start_next_timer.cancel() - start_next_timer = None - break + if start_next: + done = await _wait_one([*tasks, start_next], loop) + if done is start_next: + # The current task has failed or the timer has expired + # so we need to start the next task. + if start_next_timer: + start_next_timer.cancel() + start_next_timer = None + break + else: + done = await _wait_one(tasks, loop) if TYPE_CHECKING: assert isinstance(done, asyncio.Task)