Fixed bug in WaitGroup example (#1809)

This commit is contained in:
Dewald Swanepoel 2022-04-04 14:14:16 +02:00 committed by GitHub
parent 03a14640d7
commit 5a312cd79e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

4
go.md
View File

@ -431,7 +431,7 @@ func main() {
for _, item := range itemList {
// Increment WaitGroup Counter
wg.Add(1)
go doOperation(item)
go doOperation(&wg, item)
}
// Wait for goroutines to finish
wg.Wait()
@ -441,7 +441,7 @@ func main() {
{: data-line="1,4,8,12"}
```go
func doOperation(item string) {
func doOperation(wg *sync.WaitGroup, item string) {
defer wg.Done()
// do operation on item
// ...