Interesting, the Killable function caught my eye because I’m not aware of any facilities in Go that allows arbitrarily stopping the execution of a goroutine. Yet, the function documentation says:
Starts a job and returns a channel for cancellation signal. Once a message is sent to the channel, stops the fn.
I looked at the code for the function, and it seems like “killing” really means “stop waiting on the execution of fn.”
Question for OP: what kinds of things do you work on where these sorts of patterns are useful? (I’ve been writing Go for years and haven’t yet had much use for cool things like this.)
It should be appropriately named. Timeout or Ignore
Since Go has shared-memory concurrency (even though you’re discouraged from using it), arbitrarily stopping the execution of a goroutine could lead to corrupt program state. Java included such a facility, but as a result, it’s deprecated.
(Why? If you die while holding a lock, nobody can undo what you did, and hilarity ensues, like Office Space.)