adhocteam / pushup

Pushup is for making modern, page-oriented web apps in Go
https://pushup.adhoc.dev
MIT License
839 stars 30 forks source link

Use Go 1.20's new context.WithCancelCause #104

Closed paulsmith closed 1 year ago

paulsmith commented 1 year ago

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.