// +build ignore,OMIT | |
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
// STARTMAIN1 OMIT | |
type Ball struct{ hits int } | |
func main() { | |
table := make(chan *Ball) // HL | |
go player("ping", table) | |
table <- new(Ball) // game on; toss the ball | |
time.Sleep(1 * time.Second) | |
<-table // game over; grab the ball | |
} | |
func player(name string, table chan *Ball) { | |
for i := 0; ; i++ { | |
ball := <-table // HL | |
ball.hits++ | |
fmt.Println(name, i, "hit", ball.hits) | |
time.Sleep(100 * time.Millisecond) | |
table <- ball // HL | |
} | |
} | |
// STOPMAIN1 OMIT |