From ac55d9ff0b588b91202ccad72ee71e508e33ad08 Mon Sep 17 00:00:00 2001 From: bd Date: Sat, 19 Jul 2025 22:21:10 -0600 Subject: Reformat repository to allow for new unit tests --- t/random_wait.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 t/random_wait.py (limited to 't/random_wait.py') diff --git a/t/random_wait.py b/t/random_wait.py new file mode 100644 index 0000000..2cfc290 --- /dev/null +++ b/t/random_wait.py @@ -0,0 +1,22 @@ +# SuperFastPython.com +# example of waiting for all tasks to complete +from random import random +import asyncio + +total = 0 + + +async def task_coro(arg): + value = random() + total += value + await asyncio.sleep(value) + print(f'>{arg} done in {value}') + + +async def main(): + tasks = [asyncio.create_task(task_coro(i)) for i in range(10)] + done, pending = await asyncio.wait(tasks) + print(f'All done. Total waiting time: {total}') + + +asyncio.run(main()) -- cgit v1.2.3