From 88de10fea9058f5fdd5ff0cbba192af7779c616d Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 30 Sep 2024 12:18:51 -0500 Subject: [PATCH] avoid consuming iterable --- src/aiohappyeyeballs/_staggered.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/aiohappyeyeballs/_staggered.py b/src/aiohappyeyeballs/_staggered.py index 15d4dc7..3ba47db 100644 --- a/src/aiohappyeyeballs/_staggered.py +++ b/src/aiohappyeyeballs/_staggered.py @@ -164,15 +164,8 @@ async def run_one_coro( assert isinstance(done, asyncio.Task) tasks.discard(done) - try: - if winner := done.result(): - return *winner, exceptions - finally: - # Make sure the Timer is cancelled if the task is going - # to raise KeyboardInterrupt or SystemExit. - if start_next_timer: - start_next_timer.cancel() - + if winner := done.result(): + return *winner, exceptions finally: # We either have a winner or a KeyboardInterrupt # or SystemExit. @@ -180,6 +173,8 @@ async def run_one_coro( # If there are any tasks left, cancel them and than # wait them so they fill the exceptions list. # + if start_next_timer: + start_next_timer.cancel() for task in tasks: task.cancel() with contextlib.suppress(asyncio.CancelledError):