Skip to content

Use Go 1.20's new context.WithCancelCause#104

Merged
paulsmith merged 6 commits intomainfrom
go120-ctx-cause
Feb 6, 2023
Merged

Use Go 1.20's new context.WithCancelCause#104
paulsmith merged 6 commits intomainfrom
go120-ctx-cause

Conversation

@paulsmith
Copy link
Contributor

@paulsmith paulsmith commented Feb 3, 2023

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.

Copy link
Contributor

@llimllib llimllib left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplifies a whole bunch of stuff!

@paulsmith paulsmith merged commit 0740c07 into main Feb 6, 2023
@paulsmith paulsmith deleted the go120-ctx-cause branch February 6, 2023 19:55
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.
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

Successfully merging this pull request may close these issues.

2 participants