Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AsyncChannel] Question: is task cancellation in sending operations too violent? #182

Closed
twittemb opened this issue Jul 22, 2022 · 3 comments

Comments

@twittemb
Copy link
Contributor

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 ?

@twittemb twittemb changed the title [AsyncChannel] Question: is task cancellation in sending to violent? [AsyncChannel] Question: is task cancellation in sending operations too violent? Jul 22, 2022
@twittemb
Copy link
Contributor Author

twittemb commented Jul 23, 2022

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 ?

@twittemb
Copy link
Contributor Author

#184

@twittemb
Copy link
Contributor Author

PR is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant