Created
August 12, 2015 11:28
-
-
Save ainoya/ec84de5a03b269209638 to your computer and use it in GitHub Desktop.
golang select receives close signal anyway
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
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