Created
July 12, 2019 20:33
-
-
Save varas/e4dfe8a53c100e459633bb5aaa1361b4 to your computer and use it in GitHub Desktop.
Ensure closing an open channel via select is feasible?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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