Stop() for Ticker to enable leak-free code

This commit is contained in:
Mikhail Mazurskiy
2018-03-31 19:41:43 +11:00
parent 9847c8ee0a
commit 1f393cdef9
6 changed files with 69 additions and 35 deletions

View File

@@ -62,10 +62,11 @@ func generateLogs(linesTotal int, duration time.Duration) {
delay := duration / time.Duration(linesTotal)
rand.Seed(time.Now().UnixNano())
tick := time.Tick(delay)
ticker := time.NewTicker(delay)
defer ticker.Stop()
for id := 0; id < linesTotal; id++ {
glog.Info(generateLogLine(id))
<-tick
<-ticker.C
}
}