Closed
Description
As previously discussed on issues such as #21521 and #16472, or on several other places handling POSIX signals through context seems to be somewhat useful (and a little bit hard to do correctly?), and I would like to propose a way to handle it by adding a new signal.WithContext function.
There's also an idea to improve the current approach to handling signals (see #21521 (comment)). I didn't give it a try yet, unfortunately. I only found the earlier proposals here after trying to write some code, so I decided to create this new issue anyway to share my idea.
People using some sort of it or talking about the subject:
- https://github.com/henvic/ctxsignal (package I wrote a while ago)
- https://twitter.com/dmitshur/status/1227777318162030592 (thread)
- https://twitter.com/matryer/status/869096368039710720 (thread)
- Make Ctrl+C cancel the context.Context (blog post)
- oklog/run@9c53bcd
- https://github.com/FiloSottile/mostly-harmless/blob/22c6a9e08ad95b602b470652ad2d401d8750e264/covfefe/covfefe.go#L118-L139
- https://github.com/shurcooL/home/blob/d0f5a32e4901b05ae9979b1a9e7b67caba549778/main.go#L61-L73
- https://github.com/search?l=Go&p=1&q=context+signal&type=Repositories lists 18 other packages for the same thing.