Skip to content

Instantly share code, notes, and snippets.

@gerep
Last active March 3, 2016 20:44
Show Gist options
  • Save gerep/e670cfaf1db89b756173 to your computer and use it in GitHub Desktop.
Save gerep/e670cfaf1db89b756173 to your computer and use it in GitHub Desktop.
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)
time.Sleep(1 * time.Second)
<-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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment