diff --git a/design/mvp/canonical-abi/definitions.py b/design/mvp/canonical-abi/definitions.py index 2dd0ea0b..2ff543f8 100644 --- a/design/mvp/canonical-abi/definitions.py +++ b/design/mvp/canonical-abi/definitions.py @@ -315,20 +315,22 @@ async def default_on_block(f): await current_task.acquire() return v -async def call_and_handle_blocking(callee): +class Blocked: pass + +async def call_and_handle_blocking(callee, *args) -> Blocked|any: blocked = asyncio.Future() async def on_block(f): if not blocked.done(): - blocked.set_result(True) + blocked.set_result(Blocked()) else: current_task.release() v = await f await current_task.acquire() return v async def do_call(): - await callee(on_block) + ret = await callee(*args, on_block) if not blocked.done(): - blocked.set_result(False) + blocked.set_result(ret) else: current_task.release() asyncio.create_task(do_call()) @@ -1454,13 +1456,14 @@ async def canon_lower(opts, ft, callee, task, flat_args): async def do_call(on_block): await callee(task, subtask.on_start, subtask.on_return, on_block) [] = subtask.finish() - if await call_and_handle_blocking(do_call): - subtask.notify_supertask = True - task.need_to_drop += 1 - i = task.inst.async_subtasks.add(subtask) - flat_results = [pack_async_result(i, subtask.state)] - else: - flat_results = [0] + match await call_and_handle_blocking(do_call): + case Blocked(): + subtask.notify_supertask = True + task.need_to_drop += 1 + i = task.inst.async_subtasks.add(subtask) + flat_results = [pack_async_result(i, subtask.state)] + case _: + flat_results = [0] return flat_results def pack_async_result(i, state):