Code Room
Code reviewHardcr-g236
Subject Channel misuseLevel Senior–Staff~40 minCommon in Code quality & review interviewsIndustries Software development

Question

Review this Go event loop that disables a branch by nil-ing a channel.

The author disables a branch by setting the channel to nil. Where's the concurrency/lifecycle bug?

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 loop(in <-chan int, done <-chan struct{}) {    var ticks <-chan time.Time    ticker := time.NewTicker(time.Second)    ticks = ticker.C    for {        select {        case v := <-in:            if v < 0 {                ticks = nil          // (1) disable ticks branch            }            handle(v)        case <-ticks:            flush()        case <-done:            ticker.Stop()            return                   // (2)        }    }}
Run or narrate your approach, then ask the coach.