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

proposal: context: new method WithCallbackOnCancel(...) #57325

Closed
halturin opened this issue Dec 15, 2022 · 6 comments
Closed

proposal: context: new method WithCallbackOnCancel(...) #57325

halturin opened this issue Dec 15, 2022 · 6 comments

Comments

@halturin
Copy link

It would be great to have context.WithCallbackOnCancel(...) in order to get rid of goroutine usage to read the canceling channel.
Is there any chance to see it in the near future?

@gopherbot gopherbot added this to the Proposal milestone Dec 15, 2022
@halturin halturin changed the title proposal: affected/package: context proposal: affected/package: context.WithCallbackOnCancel(...) Dec 15, 2022
@halturin halturin changed the title proposal: affected/package: context.WithCallbackOnCancel(...) proposal: context: new method WithCallbackOnCancel(...) Dec 15, 2022
@seankhliao
Copy link
Member

Why should this be in the standard library? https://go.dev/doc/faq#x_in_std
What are the semantics of a blocking callback?

@halturin
Copy link
Author

halturin commented Dec 15, 2022

https://go.dev/doc/faq#x_in_std

not sure how it answers my proposal

What are the semantics of a blocking callback?

this callback can be running in a new goroutine, so it won't be blocked. it could be a simple func() with no return value. The main idea is to be able to trigger on canceling without keeping the running goroutine for checking the context state.

@halturin
Copy link
Author

halturin commented Dec 15, 2022

for downvoters: read this proposal as "event driven" vs "polling" approach.

@seankhliao
Copy link
Member

<-ctx.Done() is also event driven and not polling.

@halturin
Copy link
Author

halturin commented Dec 15, 2022

<-ctx.Done() is also event driven and not polling.

sorry, but it has nothing in common with "event driven". its literally "polling" approach

@seankhliao
Copy link
Member

Given that we currently have a canonical way to do this, and it hasn't been demonstrated to be a widespread need (eg by third party libraries implementing custom contexts with this feature), I think https://go.dev/doc/faq#x_in_std is the best answer.

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2022
@golang golang locked and limited conversation to collaborators Dec 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants