github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2013/advconc/pingpongpanic/pingpongpanic.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)
    15  	go player("ping", table)
    16  	go player("pong", table)
    17  
    18  	table <- new(Ball) // game on; toss the ball
    19  	time.Sleep(1 * time.Second)
    20  	<-table // game over; grab the ball
    21  
    22  	panic("show me the stacks") // HL
    23  }
    24  
    25  func player(name string, table chan *Ball) {
    26  	for {
    27  		ball := <-table
    28  		ball.hits++
    29  		fmt.Println(name, ball.hits)
    30  		time.Sleep(100 * time.Millisecond)
    31  		table <- ball
    32  	}
    33  }
    34  
    35  // STOPMAIN1 OMIT