Skip to content

Commit

Permalink
avoid consuming iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco committed Sep 30, 2024
1 parent 4dd8a72 commit 88de10f
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/aiohappyeyeballs/_staggered.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,17 @@ 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.
#
# 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):
Expand Down

0 comments on commit 88de10f

Please sign in to comment.