Code RoomWaitGroup.Add called in goroutine
HardPrep Room Coding #1654

WaitGroup.Add called in goroutine

Code reviewConcurrencySenior–Staff~26 min

Review this Go batch runner.

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.

0:00 of about 26 min
Mark a line and say what kind of problem it is.0 findings
1func runAll(jobs []Job) []Result {
2 var wg sync.WaitGroup
3 results := make([]Result, len(jobs))
4 for i, j := range jobs {
5 go func(i int, j Job) {
6 wg.Add(1)
7 defer wg.Done()
8 results[i] = run(j)
9 }(i, j)
10 }
11 wg.Wait()
12 return results
13}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.