diff options
| -rw-r--r-- | main.go | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "time" +) + +type Ball struct{ hits int } + +func main() { + table := make(chan *Ball) + go player("ping", table) + go player("pong", table) + + table <- new(Ball) + + // Make the game last this long. + time.Sleep(1 * time.Second) + + // Game over: grab the ball. + <-table +} + +func player(name string, table chan *Ball) { + for { + ball := <-table + ball.hits++ + fmt.Println(name, ball.hits) + time.Sleep(100 * time.Millisecond) + table <- ball + } +} |
