Note: I searched this topic with google, and read nearly everything I can find, but still cannot get a proper/reasonable/production ready answer.
Basically all answers are similar, just like this one: how to stop a groutine, all in same pattern, no exception: the real work is fmt.Println(1)
to print something, or simply be // Do other stuff
,
But if keep the real work at for select default case branch
, then it will be executed multiple times, for printing something it is fine, but clearly it is not ready for real work.
The only valid approach I can imagine is put the real work on a case branch then send only one signal to that case to notify it to start, like here: playground, but just feel wried, also with this approach, does it create some issues potentially?
Added code fragments to show exactly what i am trying to achieve: https://play.golang.org/p/7xjjiW7XdoQ, i want to achieve when client close connection, then immediately terminate my handler, release the resources, and quit unconditionally.