Skip to content

Commit 7fd71ac

Browse files
committed
Tidy CABI Python code a bit
1 parent 9a0e59b commit 7fd71ac

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

design/mvp/CanonicalABI.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,24 +821,27 @@ The `Task.wait_on` method defines how to block the current task on a given
821821
Python [awaitable] using the `OnBlock` callback described above:
822822
```python
823823
async def wait_on(self, awaitable, sync, cancellable = False) -> bool:
824-
awaitable = asyncio.ensure_future(awaitable)
825-
assert(not self.inst.calling_sync_import)
826824
if sync:
825+
assert(not self.inst.calling_sync_import)
827826
self.inst.calling_sync_import = True
828827
else:
829828
self.maybe_start_pending_task()
829+
830+
awaitable = asyncio.ensure_future(awaitable)
830831
cancelled = await self.on_block(awaitable)
831832
if cancelled and not cancellable:
832833
assert(self.state == Task.State.INITIAL)
833834
self.state = Task.State.PENDING_CANCEL
834835
cancelled = await self.on_block(awaitable)
835836
assert(not cancelled)
837+
836838
if sync:
837839
self.inst.calling_sync_import = False
838840
self.inst.async_waiting_tasks.notify_all()
839841
else:
840842
while self.inst.calling_sync_import:
841843
await self.inst.async_waiting_tasks.wait()
844+
842845
return cancelled
843846
```
844847
If `wait_on` is called with `sync` set to `True`, only tasks in *other*

design/mvp/canonical-abi/definitions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,24 +531,27 @@ def maybe_start_pending_task(self):
531531
return
532532

533533
async def wait_on(self, awaitable, sync, cancellable = False) -> bool:
534-
awaitable = asyncio.ensure_future(awaitable)
535-
assert(not self.inst.calling_sync_import)
536534
if sync:
535+
assert(not self.inst.calling_sync_import)
537536
self.inst.calling_sync_import = True
538537
else:
539538
self.maybe_start_pending_task()
539+
540+
awaitable = asyncio.ensure_future(awaitable)
540541
cancelled = await self.on_block(awaitable)
541542
if cancelled and not cancellable:
542543
assert(self.state == Task.State.INITIAL)
543544
self.state = Task.State.PENDING_CANCEL
544545
cancelled = await self.on_block(awaitable)
545546
assert(not cancelled)
547+
546548
if sync:
547549
self.inst.calling_sync_import = False
548550
self.inst.async_waiting_tasks.notify_all()
549551
else:
550552
while self.inst.calling_sync_import:
551553
await self.inst.async_waiting_tasks.wait()
554+
552555
return cancelled
553556

554557
async def call_sync(self, callee, on_start, on_return):

0 commit comments

Comments
 (0)