Code Room
Code reviewMediumcr-g229
Subject Channel misuseLevel Mid–Senior~25 minCommon in Code quality & review interviewsIndustries Software development

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.

Talk through your review
Code to reviewgo
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.