Code Room
Code reviewMedium
Question
Review this Go worker pool that closes a results channel.
What's the race in how the channel is closed?
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.
Learn the concepts
func process(jobs []Job) []Result { out := make(chan Result, len(jobs)) var wg sync.WaitGroup for _, j := range jobs { wg.Add(1) go func(j Job) { defer wg.Done() out <- run(j) }(j) } go func() { close(out) }() // (1) var rs []Result for r := range out { // (2) rs = append(rs, r) } wg.Wait() return rs}Run or narrate your approach, then ask the coach.