Skip to content

Commit

Permalink
Exception must be handle in task group
Browse files Browse the repository at this point in the history
  • Loading branch information
khiemdoan committed Oct 4, 2023
1 parent 368725d commit 405ac74
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion docs_src/tutorial/soonify_return/tutorial002.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ async def do_work(name: str):


async def get_data():
ex = None

async with asyncer.create_task_group() as task_group:
soon_value1 = task_group.soonify(do_work)(name="Yury")
soon_value2 = task_group.soonify(do_work)(name="Nathaniel")
soon_value3 = task_group.soonify(do_work)(name="Alex")
print(soon_value1.value)
try:
print(soon_value1.value)
except asyncer.PendingValueException as _ex:
ex = _ex

if ex is not None:
raise ex

data = [soon_value1.value, soon_value2.value, soon_value3.value]
return data
Expand Down

0 comments on commit 405ac74

Please sign in to comment.