Coverage for docs_src/tutorial/soonify_return/tutorial003.py: 100%
21 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 01:12 +0000
« prev ^ index » next coverage.py v7.6.1, created at 2024-09-09 01:12 +0000
1import anyio 1abcde
2import asyncer 1abcde
5async def do_work(name: str): 1abcde
6 await anyio.sleep(1) 1abcde
7 message = f"Hello, {name}" 1abcde
8 return message 1abcde
11async def get_data(): 1abcde
12 async with asyncer.create_task_group() as task_group: 1abcde
13 soon_value1 = task_group.soonify(do_work)(name="Yury") 1abcde
14 await anyio.sleep(2) 1abcde
15 if soon_value1.ready: 1abcde
16 print(f"Preview value1: {soon_value1.value}") 1abcde
17 soon_value2 = task_group.soonify(do_work)(name="Nathaniel") 1abcde
18 soon_value3 = task_group.soonify(do_work)(name="Alex") 1abcde
20 data = [soon_value1.value, soon_value2.value, soon_value3.value] 1abcde
21 return data 1abcde
24async def main(): 1abcde
25 data = await get_data() 1abcde
26 for message in data: 1abcde
27 print(message) 1abcde
30anyio.run(main) 1abcde