Created
February 2, 2017 07:40
-
-
Save YanhaoYang/6a68bda7f033d2440654372b441d86bd to your computer and use it in GitHub Desktop.
Ensure channel is closed, but not close it twice
This file contains hidden or 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
done := make(chan struct{}) | |
defer func(c chan struct{}) { | |
select { | |
case <-c: | |
default: | |
close(c) | |
} | |
}(done) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment