From 67e7ebf8c507f2f02cff0866e3ccf48032f20b16 Mon Sep 17 00:00:00 2001 From: demo Date: Sun, 24 May 2026 10:01:53 -0400 Subject: refactor: move game code into testable function --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'main.go') diff --git a/main.go b/main.go index 7e2180a..c812764 100644 --- a/main.go +++ b/main.go @@ -12,6 +12,10 @@ func main() { numSecs := flag.Int("s", 1, "Number of seconds game should last") flag.Parse() + game(*numSecs) +} + +func game(numSecs int) { table := make(chan Ball) go player("ping", table) go player("pong", table) @@ -19,7 +23,7 @@ func main() { table <- Ball{} // Make the game last this long. - time.Sleep(time.Duration(*numSecs) * time.Second) + time.Sleep(time.Duration(numSecs) * time.Second) // Game over: grab the ball. <-table -- cgit v1.2.3