github.com/april1989/origin-go-tools@v0.0.32/cmd/guru/testdata/src/peers/main.go (about) 1 package main 2 3 // Tests of channel 'peers' query. 4 // See go.tools/guru/guru_test.go for explanation. 5 // See peers.golden for expected query results. 6 7 var a2 int 8 9 func main() { 10 chA := make(chan *int) 11 a1 := 1 12 chA <- &a1 13 14 chA2 := make(chan *int, 2) 15 if a2 == 0 { 16 chA = chA2 17 } 18 19 chB := make(chan *int) 20 b := 3 21 chB <- &b 22 23 <-chA // @pointsto pointsto-chA "chA" 24 <-chA2 // @pointsto pointsto-chA2 "chA2" 25 <-chB // @pointsto pointsto-chB "chB" 26 27 select { 28 case rA := <-chA: // @peers peer-recv-chA "<-" 29 _ = rA // @pointsto pointsto-rA "rA" 30 case rB := <-chB: // @peers peer-recv-chB "<-" 31 _ = rB // @pointsto pointsto-rB "rB" 32 33 case <-chA: // @peers peer-recv-chA' "<-" 34 35 case chA2 <- &a2: // @peers peer-send-chA' "<-" 36 } 37 38 for range chA { 39 } 40 41 close(chA) // @peers peer-close-chA "chA" 42 43 chC := make(chan *int) 44 (close)(chC) // @peers peer-close-chC "chC" 45 46 close := func(ch chan *int) chan *int { 47 return ch 48 } 49 50 close(chC) <- &b // @peers peer-send-chC "chC" 51 <-close(chC) // @peers peer-recv-chC "chC" 52 }