Skip to content

Instantly share code, notes, and snippets.

@YanhaoYang
Created February 2, 2017 07:40
Show Gist options
  • Save YanhaoYang/6a68bda7f033d2440654372b441d86bd to your computer and use it in GitHub Desktop.
Save YanhaoYang/6a68bda7f033d2440654372b441d86bd to your computer and use it in GitHub Desktop.
Ensure channel is closed, but not close it twice
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