Fixed bug in WaitGroup example (#1809)
This commit is contained in:
parent
03a14640d7
commit
5a312cd79e
4
go.md
4
go.md
|
@ -431,7 +431,7 @@ func main() {
|
||||||
for _, item := range itemList {
|
for _, item := range itemList {
|
||||||
// Increment WaitGroup Counter
|
// Increment WaitGroup Counter
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go doOperation(item)
|
go doOperation(&wg, item)
|
||||||
}
|
}
|
||||||
// Wait for goroutines to finish
|
// Wait for goroutines to finish
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
@ -441,7 +441,7 @@ func main() {
|
||||||
{: data-line="1,4,8,12"}
|
{: data-line="1,4,8,12"}
|
||||||
|
|
||||||
```go
|
```go
|
||||||
func doOperation(item string) {
|
func doOperation(wg *sync.WaitGroup, item string) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
// do operation on item
|
// do operation on item
|
||||||
// ...
|
// ...
|
||||||
|
|
Loading…
Reference in New Issue