←back to thread

Go subtleties

(harrisoncramer.me)
234 points darccio | 1 comments | | HN request time: 0s | source
Show context
acatton ◴[] No.45667905[source]
> The wg.Go Function

> Go 1.25 introduced a waitgroup.Go function that lets you add Go routines to a waitgroup more easily. It takes the place of using the go keyword, [...]

99% of the time, you don't want to use sync.WaitGroup, but rather errgroup.Group. This is basically sync.WaitGroup with error handling. It also has optional context/cancellation support. See https://pkg.go.dev/golang.org/x/sync/errgroup

I know it's not part of the standard library, but it's part of the http://golang.org/x/ packages. TBH, golang.org/x/ is stuff that should be in the standard library but isn't, for some reason.

replies(5): >>45668472 #>>45669297 #>>45669628 #>>45671829 #>>45672717 #
lagniappe ◴[] No.45669297[source]
>golang.org/x/ is stuff that should be in the standard library but isn't, for some reason

think of it as testing/staging before being merged into stable stdlib

replies(2): >>45672531 #>>45673067 #
1. CamouflagedKiwi ◴[] No.45673067[source]
Except that it's a little bit too convenient, and highly useful things like errgroup stay there instead of having been adopted into the stdlib.