summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordemo <demo@antix1>2026-05-24 09:44:43 -0400
committerdemo <demo@antix1>2026-05-24 09:44:43 -0400
commitc9c781bdc435fe19f51ae457da315c42d1c4a024 (patch)
treea1a489ea782fed6361005ae21c6106785c45249e
parentcc6069567082a464a82e6e7a95fe906268c33a3e (diff)
feat: copy ping-pong example
-rw-r--r--main.go32
1 files changed, 32 insertions, 0 deletions
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
+ }
+}