From 66c785a5739fb42dcd3bf54def1e0412c453b0b6 Mon Sep 17 00:00:00 2001 From: Johan Mena Date: Thu, 23 Oct 2025 15:51:45 -0400 Subject: [PATCH 1/4] Update WaitGroup example Go 1.25 introduced https://pkg.go.dev/sync#WaitGroup, which simplified waiting for goroutines to finish. This PR updates the code example that uses WaitGroups. --- src/goroutine-exit.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/goroutine-exit.md b/src/goroutine-exit.md index 6cc5b42a..01042cc9 100644 --- a/src/goroutine-exit.md +++ b/src/goroutine-exit.md @@ -4,17 +4,13 @@ Given a goroutine spawned by the system, there must be a way to wait for the goroutine to exit. There are two popular ways to do this: -- Use a `sync.WaitGroup`. - Do this if there are multiple goroutines that you want to wait for +- Use a `sync.WaitGroup`, which does this with `Go` and `Wait`. + Do this if there are multiple goroutines that you want to wait for. ```go var wg sync.WaitGroup for i := 0; i < N; i++ { - wg.Add(1) - go func() { - defer wg.Done() - // ... - }() + wg.Go(...) } // To wait for all to finish: From 01b1501e73e4912540202c0cc1e4ea58d0894824 Mon Sep 17 00:00:00 2001 From: jhn <678798+jhn@users.noreply.github.com> Date: Thu, 23 Oct 2025 19:52:56 +0000 Subject: [PATCH 2/4] Auto-update style.md --- style.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/style.md b/style.md index bf0d20bb..8716a66d 100644 --- a/style.md +++ b/style.md @@ -2039,17 +2039,13 @@ Given a goroutine spawned by the system, there must be a way to wait for the goroutine to exit. There are two popular ways to do this: -- Use a `sync.WaitGroup`. - Do this if there are multiple goroutines that you want to wait for +- Use a `sync.WaitGroup`, which does this with `Go` and `Wait`. + Do this if there are multiple goroutines that you want to wait for. ```go var wg sync.WaitGroup for i := 0; i < N; i++ { - wg.Add(1) - go func() { - defer wg.Done() - // ... - }() + wg.Go(...) } // To wait for all to finish: From 0b48aed150b631c5263665960bf8488264a1eee5 Mon Sep 17 00:00:00 2001 From: Moises Vega Date: Thu, 23 Oct 2025 13:41:30 -0700 Subject: [PATCH 3/4] Update src/goroutine-exit.md --- src/goroutine-exit.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/goroutine-exit.md b/src/goroutine-exit.md index 01042cc9..9cffb919 100644 --- a/src/goroutine-exit.md +++ b/src/goroutine-exit.md @@ -4,7 +4,7 @@ Given a goroutine spawned by the system, there must be a way to wait for the goroutine to exit. There are two popular ways to do this: -- Use a `sync.WaitGroup`, which does this with `Go` and `Wait`. +- Use a `sync.WaitGroup` to wait for multiple goroutines to complete. Do this if there are multiple goroutines that you want to wait for. ```go From c6dc05575289b11c49605b9bfc3d479a1989ed31 Mon Sep 17 00:00:00 2001 From: Moises Vega Date: Thu, 23 Oct 2025 13:41:35 -0700 Subject: [PATCH 4/4] Update style.md --- style.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/style.md b/style.md index 8716a66d..6ffaff4b 100644 --- a/style.md +++ b/style.md @@ -2039,7 +2039,7 @@ Given a goroutine spawned by the system, there must be a way to wait for the goroutine to exit. There are two popular ways to do this: -- Use a `sync.WaitGroup`, which does this with `Go` and `Wait`. +- Use a `sync.WaitGroup` to wait for multiple goroutines to complete. Do this if there are multiple goroutines that you want to wait for. ```go