teivah/100-go-mistakes

To stop ticker explicitly

maliyan opened this issue · 1 comments

10.1 #75 Providing a wrong time duration should stop ticker, or cause leaks

ticker := time.NewTicker(1000) // should stop defer
for {
    select {
    case <-ticker.C:
        // Do something
    }
}
ticker := time.NewTicker(1000)
defer ticker.Stop()
for {
    select {
    case <-ticker.C:
        // Do something
    }
}

Thanks but this code is an excerpt (we don't see the whole function) and don't focus on the ticker so I don't consider it an issue.