Skip to content

Instantly share code, notes, and snippets.

@varas
Created July 12, 2019 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varas/e4dfe8a53c100e459633bb5aaa1361b4 to your computer and use it in GitHub Desktop.
Save varas/e4dfe8a53c100e459633bb5aaa1361b4 to your computer and use it in GitHub Desktop.
Ensure closing an open channel via select is feasible?
// Being Stop called several times
// Besides the race condition btw channel read & close
// Given that select is non-deterministic
// Would this work without panicking?
func Stop() {
select {
case _, open := <-sender.stopChannel:
if open {
close(sender.stopChannel)
}
default:
close(sender.stopChannel)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment