Skip to content

Instantly share code, notes, and snippets.

@siburu
Created December 7, 2015 07:22
Show Gist options
  • Save siburu/a3f6731e6cf846f1dcb6 to your computer and use it in GitHub Desktop.
Save siburu/a3f6731e6cf846f1dcb6 to your computer and use it in GitHub Desktop.
In select statement, reading from a closed channel is selected immediately without going to a default case.
package main
func main() {
ch := make(chan struct{})
close(ch)
/*
for _ = range ch {
}
*/
for {
select {
case <-ch:
default:
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment