Update WaitGroup usage instructions for Go 1.25 to include new Go method syntax

This commit is contained in:
sauran 2025-10-01 04:22:44 +05:00
parent bbed5c15a5
commit 94d5157bf2

View File

@ -174,7 +174,13 @@ Follow idiomatic Go practices and community standards when writing Go code. Thes
- Choose between channels and mutexes based on the use case: use channels for communication, mutexes for protecting state - Choose between channels and mutexes based on the use case: use channels for communication, mutexes for protecting state
- Use `sync.Once` for one-time initialization - Use `sync.Once` for one-time initialization
- WaitGroup usage by Go version: - WaitGroup usage by Go version:
- If `go >= 1.25` in `go.mod`, use the new `WaitGroup` pattern - If `go >= 1.25` in `go.mod`, use the new `WaitGroup.Go` method ([documentation](https://pkg.go.dev/sync#WaitGroup)):
```go
var wg sync.WaitGroup
wg.Go(task1)
wg.Go(task2)
wg.Wait()
```
- If `go < 1.25`, use the classic `Add`/`Done` pattern - If `go < 1.25`, use the classic `Add`/`Done` pattern
## Error Handling Patterns ## Error Handling Patterns