Skip to content

Instantly share code, notes, and snippets.

@zhyon404
Created November 14, 2017 08:11
Show Gist options
  • Save zhyon404/c93eb52b02803d97a9e17046e530dc6a to your computer and use it in GitHub Desktop.
Save zhyon404/c93eb52b02803d97a9e17046e530dc6a to your computer and use it in GitHub Desktop.
if channel is closed
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