1func processAll(items []string) {
2 var wg sync.WaitGroup
3 for _, item := range items {
4 wg.Add(1)
5 go func() {
6 defer wg.Done()
7 fmt.Println(item)
8 }()
9 }
10 wg.Wait()
11}
no lines flagged
#066PracticeMedium15 min · 120 XP
Loop Variable Captured by Reference in Goroutines
Launching a goroutine per item in a loop prints the same final value for every goroutine instead of each item.
Flagged linesNo lines flagged yet
What's wrong?
Flag a line or write a note to submit.