blob: df3c5637b37c2ea7fb45acefcf8b5a1ba5835102 [file] [log] [blame]
// +build OMIT
package main
import (
"fmt"
"time"
)
// STARTMAIN1 OMIT
type Ball struct{ hits int }
func main() {
in, out := make(chan *Ball), make(chan *Ball) // HL
go player("ping", in, out)
go player("pong", in, out)
go func() {
for i := 0; i < 8; i++ {
in <- new(Ball) // feed the pipeline // HL
}
}()
for i := 0; i < 8; i++ {
<-out // drain the pipeline // HL
}
}
func player(name string, in <-chan *Ball, out chan<- *Ball) { // HL
for i := 0; ; i++ {
ball := <-in // HL
ball.hits++
fmt.Println(name, i, "hit", ball.hits)
time.Sleep(100 * time.Millisecond)
out <- ball // HL
}
}
// STOPMAIN1 OMIT