Skip to content

Instantly share code, notes, and snippets.

@ainoya
Created August 12, 2015 11:28
Show Gist options
  • Save ainoya/ec84de5a03b269209638 to your computer and use it in GitHub Desktop.
Save ainoya/ec84de5a03b269209638 to your computer and use it in GitHub Desktop.
golang select receives close signal anyway
package main
import "fmt"
func main() {
var a chan struct{}
fmt.Println("Hello, playground")
a = make(chan struct{})
go func(){
close(a)
}()
fmt.Println("receive1 select")
select {
case p:= <-a:
fmt.Printf("receive1: %+v\n", p)
fmt.Println("close received")
}
fmt.Println("receive2 select")
select {
case p:= <-a:
fmt.Printf("receive2: %+v\n", p)
fmt.Println("close received")
}
fmt.Println("closing")
c:= <-a
fmt.Printf("closed: %+v\n", c)
}
//http://play.golang.org/p/RxNrLJ_GOa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment