Something that I don't see style guides addressing, but think they should, is how to cancel work when the caller no longer cares about the answer. (Consider an aborted RPC, or someone pressing the "stop" button in their browser.) A lot of people will do things like: func (s *Server) HandleFoo(ctx context.Context, in *input) status { ch This will block on the channel write even if the context becomes cancelled. Instea…
so in your example it should be done like this: ch and the 'workFor' function should be the one that gets canceled with the context.
Deep down at the very end, you would have select statement with 'Of course the world isn't perfect and not everything takes context right now (even in standard library), so you do have to do some workarounds every once in a while.