Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumGoerrgroup and fan-outSingle-choice MCQ

In a fan-out where each worker writes to a shared results slice indexed by its own loop index, the code below is run with errgroup. Is there a data race on results?

results := make([]int, len(items)) g := new(errgroup.Group) for i, it := range items { i, it := i, it g.Go(func() error { results[i] = compute(it) return nil }) } _ = g.Wait()