From c9c781bdc435fe19f51ae457da315c42d1c4a024 Mon Sep 17 00:00:00 2001 From: demo Date: Sun, 24 May 2026 09:44:43 -0400 Subject: feat: copy ping-pong example --- main.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..faf3519 --- /dev/null +++ b/main.go @@ -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 + } +} -- cgit v1.2.3