Waitgroups: What They Are, How to Use Them and What Changed with Go 1.25
Posted5 months agoActive5 months ago
mfbmina.devTechstory
calmpositive
Debate
40/100
Go Programming LanguageConcurrencyWaitgroups
Key topics
Go Programming Language
Concurrency
Waitgroups
The article discusses the WaitGroup feature in Go, its usage, and changes introduced in Go 1.25, sparking a discussion on its utility and comparison to other concurrency approaches.
Snapshot generated from the HN discussion
Discussion Activity
Very active discussionFirst comment
25m
Peak period
21
0-2h
Avg / period
5.9
Comment distribution47 data points
Loading chart...
Based on 47 loaded comments
Key moments
- 01Story posted
Aug 23, 2025 at 11:21 AM EDT
5 months ago
Step 01 - 02First comment
Aug 23, 2025 at 11:46 AM EDT
25m after posting
Step 02 - 03Peak activity
21 comments in 0-2h
Hottest window of the conversation
Step 03 - 04Latest activity
Aug 24, 2025 at 8:22 PM EDT
5 months ago
Step 04
Generating AI Summary...
Analyzing up to 500 comments to identify key contributors and discussion patterns
ID: 44996623Type: storyLast synced: 11/20/2025, 9:01:20 PM
Want the full context?
Jump to the original sources
Read the primary article or dive into the live Hacker News thread when you're ready.
just `var wg sync.WaitGroup`, it is cleaner this way
cool it down a little. touch some grass. and hopefully you will see beauty in Go zero-values :P
here is google guideline: https://google.github.io/styleguide/go/best-practices#declar...
For example, if you want to set a variable to the number of seconds in seven hours, you could just set the variable to 25200, or you could set it to 60 * 60 * 7. The expanded version might be clearer in the code context, but in the end they do exactly the same thing.
dont you mean a week? 60 x 60 x 24 x 7 ?
or at lest 8 hours?
7 hours is just odd
What is quite sad is that we cannot add it ourselves as it's so simple of what they have done:
errgroup also has other niceties like error propagation, context cancellation, and concurrency limiting.
At best, using the optional, higher-effort errgroup.WithContext will cancel the context but still run all of your funcs. If you don't want that for one of the funcs, or some component of them, just don't use the context.
You could also just make your subtask function return nil always, if you just want to get the automatic bookkeeping call pattern (like WaitGroup.Go from Golang 1.25), plus optional concurrency limiting.
Also note, even if a subtask function returns an error, the errgroup Wait blocking semantics are identical to those of a WaitGroup. Wait will return the first error when it returns, but it doesn't unblock early on first error.
My recommendation would be to have a NewGroup function or equivalent that returns an empty group to surface it as an alternative to WithContext.
That goes against common practices in Golang, articulated in the second paragraph of https://go.dev/doc/effective_go#allocation_new among many other places.
Also the errgroup documentation specifically says "A zero Group is valid, has no limit on the number of active goroutines, and does not cancel on error." And, as you noted, one of the examples doesn't use WithContext.
You need to use this pattern instead:
https://go.dev/blog/loopvar-preview
Well, you could...
> You need to use this pattern insteadWhy? Seems rather redundant. It is not like WaitGroup.Go exists in earlier versions.
Right, but it prevents goroutine leaks. In these situations I'm usually fine with bailing on the first error, but I grant that's not always desirable. If it's not, I would collect and join errors and return those along with partial results (if those are useful).
But channels already do the waiting part for you.
[1] https://docs.oracle.com/javase/8/docs/api/java/util/concurre...
[0] https://docs.oracle.com/javase/7/docs/api/java/util/concurre...