Skip to content

Commit

Permalink
Handle the concurrently-closed case in {stream,future}.cancel-{read,w…
Browse files Browse the repository at this point in the history
…rite}
  • Loading branch information
lukewagner committed Oct 24, 2024
1 parent 924f180 commit 3ab3c20
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
22 changes: 13 additions & 9 deletions design/mvp/CanonicalABI.md
Original file line number Diff line number Diff line change
Expand Up @@ -3090,17 +3090,21 @@ async def cancel_async_copy(HandleT, sync, task, i):
h = task.inst.waitables.get(i)
trap_if(not isinstance(h, HandleT))
trap_if(not h.copying_buffer)
if sync:
await task.call_sync(h.cancel_copy, h.copying_buffer)
flat_results = [h.copying_buffer.progress]
if h.stream.closed():
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
h.copying_buffer = None
else:
match await call_and_handle_blocking(h.cancel_copy, h.copying_buffer):
case Blocked():
flat_results = [BLOCKED]
case Returned():
flat_results = [h.copying_buffer.progress]
h.copying_buffer = None
if sync:
await task.call_sync(h.cancel_copy, h.copying_buffer)
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
h.copying_buffer = None
else:
match await call_and_handle_blocking(h.cancel_copy, h.copying_buffer):
case Blocked():
flat_results = [BLOCKED]
case Returned():
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
h.copying_buffer = None
return flat_results
```
As mentioned above for `async_copy`, if cancellation doesn't block, the
Expand Down
22 changes: 13 additions & 9 deletions design/mvp/canonical-abi/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,17 +1929,21 @@ async def cancel_async_copy(HandleT, sync, task, i):
h = task.inst.waitables.get(i)
trap_if(not isinstance(h, HandleT))
trap_if(not h.copying_buffer)
if sync:
await task.call_sync(h.cancel_copy, h.copying_buffer)
flat_results = [h.copying_buffer.progress]
if h.stream.closed():
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
h.copying_buffer = None
else:
match await call_and_handle_blocking(h.cancel_copy, h.copying_buffer):
case Blocked():
flat_results = [BLOCKED]
case Returned():
flat_results = [h.copying_buffer.progress]
h.copying_buffer = None
if sync:
await task.call_sync(h.cancel_copy, h.copying_buffer)
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
h.copying_buffer = None
else:
match await call_and_handle_blocking(h.cancel_copy, h.copying_buffer):
case Blocked():
flat_results = [BLOCKED]
case Returned():
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
h.copying_buffer = None
return flat_results

### 🔀 `canon waitable.drop`
Expand Down

0 comments on commit 3ab3c20

Please sign in to comment.