Skip to content

Commit bd79e22

Browse files
committed
Handle the concurrently-closed case in {stream,future}.cancel-{read,write}
1 parent ad67bae commit bd79e22

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

design/mvp/CanonicalABI.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3100,17 +3100,21 @@ async def cancel_async_copy(HandleT, sync, task, i):
31003100
h = task.inst.waitables.get(i)
31013101
trap_if(not isinstance(h, HandleT))
31023102
trap_if(not h.copying_buffer)
3103-
if sync:
3104-
await task.call_sync(h.cancel_copy, h.copying_buffer)
3105-
flat_results = [h.copying_buffer.progress]
3103+
if h.stream.closed():
3104+
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
31063105
h.copying_buffer = None
31073106
else:
3108-
match await call_and_handle_blocking(h.cancel_copy, h.copying_buffer):
3109-
case Blocked():
3110-
flat_results = [BLOCKED]
3111-
case Returned():
3112-
flat_results = [h.copying_buffer.progress]
3113-
h.copying_buffer = None
3107+
if sync:
3108+
await task.call_sync(h.cancel_copy, h.copying_buffer)
3109+
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
3110+
h.copying_buffer = None
3111+
else:
3112+
match await call_and_handle_blocking(h.cancel_copy, h.copying_buffer):
3113+
case Blocked():
3114+
flat_results = [BLOCKED]
3115+
case Returned():
3116+
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
3117+
h.copying_buffer = None
31143118
return flat_results
31153119
```
31163120
As mentioned above for `async_copy`, if cancellation doesn't block, the

design/mvp/canonical-abi/definitions.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1950,17 +1950,21 @@ async def cancel_async_copy(HandleT, sync, task, i):
19501950
h = task.inst.waitables.get(i)
19511951
trap_if(not isinstance(h, HandleT))
19521952
trap_if(not h.copying_buffer)
1953-
if sync:
1954-
await task.call_sync(h.cancel_copy, h.copying_buffer)
1955-
flat_results = [h.copying_buffer.progress]
1953+
if h.stream.closed():
1954+
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
19561955
h.copying_buffer = None
19571956
else:
1958-
match await call_and_handle_blocking(h.cancel_copy, h.copying_buffer):
1959-
case Blocked():
1960-
flat_results = [BLOCKED]
1961-
case Returned():
1962-
flat_results = [h.copying_buffer.progress]
1963-
h.copying_buffer = None
1957+
if sync:
1958+
await task.call_sync(h.cancel_copy, h.copying_buffer)
1959+
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
1960+
h.copying_buffer = None
1961+
else:
1962+
match await call_and_handle_blocking(h.cancel_copy, h.copying_buffer):
1963+
case Blocked():
1964+
flat_results = [BLOCKED]
1965+
case Returned():
1966+
flat_results = [pack_async_copy_result(h.copying_buffer, h)]
1967+
h.copying_buffer = None
19641968
return flat_results
19651969

19661970
### 🔀 `canon waitable.drop`

0 commit comments

Comments
 (0)