1
0
Fork 0
mirror of https://github.com/vbatts/talks.git synced 2025-06-02 01:52:30 +00:00

2016-12: brush up this talk for an intro

This commit is contained in:
Vincent Batts 2016-12-04 18:40:58 -05:00
parent 1b8e5c7a36
commit 68f582d393
18 changed files with 513 additions and 0 deletions

View file

@ -0,0 +1,33 @@
// +build OMIT
package main
import (
"fmt"
"time"
)
// STARTMAIN1 OMIT
type Ball struct{ hits int }
func main() {
table := make(chan *Ball)
go player("ping", table)
go player("pong", 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 {
ball := <-table
ball.hits++
fmt.Println(name, ball.hits)
time.Sleep(100 * time.Millisecond)
table <- ball
}
}
// STOPMAIN1 OMIT