Use Go 1.20's new context.WithCancelCause#104
Merged
Conversation
llimllib
approved these changes
Feb 6, 2023
Contributor
llimllib
left a comment
There was a problem hiding this comment.
Simplifies a whole bunch of stuff!
paulsmith
added a commit
that referenced
this pull request
Feb 15, 2023
This change switches from our hand-rolled context.Context implementation to the new WithCancelCause function in the context package of Go 1.20. We rolled our own type that implemented context.Context in order to get the ability to distinguish between sources of context cancellation, which is necessary for the behavior of the hot reloader, to tell between a file change event, which triggers the reload, and a CTRL-C or SIGTERM, which should shut down the server. With Go 1.20's addition of WithCancelCause() and Cause() in the context package, along with errors.Is(), it's much simpler to determine the source of a cancellation. This simplifies Pushup's implementation, and it's always good to use some stdlib code instead of your own jank when it makes sense. This does change Pushup's minimum dependency on Go to version 1.20, but this only applies if you are developing Pushup itself - if you are just making Pushup apps, you don't need to upgrade to 1.20.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We rolled our own type that implemented context.Context in order to get the ability to distinguish between sources of context cancellation, which is necessary for the behavior of the hot reloader, to tell between a file change event, which triggers the reload, and a CTRL-C or SIGTERM, which should shut down the server.
With Go 1.20's addition of WithCancelCause() and Cause() in the
contextpackage, along witherrors.Is(), it's much simpler to determine the source of a cancellation.This simplifies Pushup's implementation, and it's always good to use some stdlib code instead of your own jank when it makes sense.
This does change Pushup's minimum dependency on Go to version 1.20, but this only applies if you are developing Pushup itself - if you are just making Pushup apps, you don't need to upgrade to 1.20.