Created
November 14, 2017 08:11
-
-
Save zhyon404/c93eb52b02803d97a9e17046e530dc6a to your computer and use it in GitHub Desktop.
if channel is closed
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
select { | |
case <-ch: | |
// channel is closed, this is executed | |
default: | |
// channel is still open, the previous case is not executed | |
close(ch) | |
} | |
once := sync.Once{} | |
ch := make(chan bool) | |
... | |
once.Do(func() { close(ch) }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment