We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 75ecfe9 commit 7067ee1Copy full SHA for 7067ee1
1 file changed
utilities/Typing-Speed-Tester/Typing-Speed-Tester.py
@@ -48,13 +48,19 @@ async def fetch_phrase_async():
48
"https://api.quotable.io/random"
49
]
50
async with aiohttp.ClientSession() as session:
51
- tasks = [fetch_url(session, url) for url in urls]
52
- # Gather them concurrently
53
- results = await asyncio.gather(*tasks)
54
- for res in results:
55
- if res:
56
- return res
57
- return None
+ tasks = {asyncio.create_task(fetch_url(session, url)) for url in urls}
+
+ while tasks:
+ done, tasks = await asyncio.wait(tasks, return_when=asyncio.FIRST_COMPLETED)
+ for task in done:
+ result = task.result()
+ if result:
58
+ # Cancel remaining tasks — we got what we need
59
+ for t in tasks:
60
+ t.cancel()
61
+ return result
62
63
+ return None
64
65
66
def main():
0 commit comments