Use Go 1.20's new context.WithCancelCause #104
Merged
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
context
package, 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.