github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2015/go-for-java-programmers/channel.go (about) 1 // +build OMIT 2 3 package main 4 5 import ( 6 "fmt" 7 "time" 8 ) 9 10 // STARTMAIN1 OMIT 11 type Ball struct{ hits int } 12 13 func main() { 14 table := make(chan *Ball) // HL 15 go player("ping", table) 16 17 table <- new(Ball) // game on; toss the ball 18 time.Sleep(1 * time.Second) 19 <-table // game over; grab the ball 20 } 21 22 func player(name string, table chan *Ball) { 23 for i := 0; ; i++ { 24 ball := <-table // HL 25 ball.hits++ 26 fmt.Println(name, i, "hit", ball.hits) 27 time.Sleep(100 * time.Millisecond) 28 table <- ball // HL 29 } 30 } 31 32 // STOPMAIN1 OMIT