-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
context: add APIs for setting a cancelation cause when deadline or timer expires #56661
Comments
This proposal has been added to the active column of the proposals project |
Change https://go.dev/cl/449318 mentions this issue: |
https://go.dev/cl/449318 implements this proposal. The test exercises all the behaviors documented above. |
@ChrisHines, you had been vocal about these on #51365 (comment). Do you still think we should do them? I think these are probably right but I'm less sure than about #51365, so I think it would make sense to wait for Go 1.21 rather than push them through in the last days of this release. We'll have more time to fine-tune that way. |
To clarify, I can see the use of these, but personally I think there is a lot of clumsiness to both these and #51365. Much of that clumsiness is due to the need for backwards compatibility, so we are in a tight spot here. I was vocal about these in #51365 mostly because I wanted to understand how to use them properly and because it seemed we didn't properly follow through with the discussion of their ergonomics and I didn't want to see that slip through the cracks. It was said that we could omit them from the stdlib because it would be easy to implement them on top of the base I have encountered the problem of seeing a |
Does anyone object to this proposal? |
Based on the discussion above, this proposal seems like a likely accept. |
No change in consensus, so accepted. 🎉 |
This comment was marked as off-topic.
This comment was marked as off-topic.
Change https://go.dev/cl/486535 mentions this issue: |
For #40221 For #56661 For #57928 Change-Id: Iaf7425bb26eeb9c23235d13c786d5bb572159481 Reviewed-on: https://go-review.googlesource.com/c/go/+/486535 Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Sameer Ajmani <sameer@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
…mer expires Fixes golang#56661 Change-Id: I1c23ebc52e6b7ae6ee956614e1a0a45d6ecbd5b4 Reviewed-on: https://go-review.googlesource.com/c/go/+/449318 Run-TryBot: Sameer Ajmani <sameer@golang.org> Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This is a follow on to proposal #51365 to add
WithDeadlineCause
andWithTimeoutCause
to thecontext
package. These functions enable the user to arrange a cancelation cause to be set when a deadline or timer expires. This is not possible to do efficiently with the APIs introduced in https://go-review.git.corp.google.com/c/go/+/375977.The proposed API additions are:
Example:
The
cause
passed to these functions is set only when the deadline or timer expires. The common case is that the context is canceled before that happens via the returnedCancelFunc
. In this case, the cause will becontext.Canceled
:If users need to set the cause on both the timer and
cancel()
paths, they can stack contexts:Example where the timer fires first:
Example where cancel happens first:
The text was updated successfully, but these errors were encountered: