[AsyncChannel] Question: is task cancellation in sending operations too violent?
Hi @phausler
I was wondering if the task cancellation when sending an element in an AsyncChannel was not a bit too violent ?
This is the code when sending an element:
func _send(_ element: Element) async {
await withTaskCancellationHandler {
terminateAll()
} operation: { ... }
the terminateAll() function will resume all the suspended operations (producers and consumers). What if the sending operations are performed in several Tasks? it means the async channel is finished for every one of them, which seem a bit violent right ?
I guess in case of a sending cancellation, we should only make sure the sending continuation is resumed immediately, and the operation is removed from the pending list (and only that operation). If we are in the case where there is an awaiting that is being resumed by the sending then we should also check for Task.isCancelled right before resuming the awaiting and not do it if there is a cancellation ?
what do you think ?
https://github.com/apple/swift-async-algorithms/pull/184
PR is merged