mirror of
https://github.com/vbatts/talks.git
synced 2025-10-27 02:36:43 +00:00
flatten folder
This commit is contained in:
parent
5783dd7f09
commit
ffd598d420
12 changed files with 15 additions and 12 deletions
33
2015/02-devconf.cz/pingpong.go
Normal file
33
2015/02-devconf.cz/pingpong.go
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue