time.Tick
used in leaky way SCC-SA1015499 Ignores: ignores,
500 })
501
502 tick := time.Tick(1000 * time.Millisecond)503 var chgs []changes.Change
504
505 for {
428}
429
430func (opts Options2) waitForBuild(ctx context.Context, id string) error {
431 tick := time.Tick(1 * time.Second)432
433 for {
434 select {
Using time.Tick
in a way that will leak. Consider using time.NewTicker, and
only use time.Tick in tests, commands and endless functions.
import (
"fmt"
"time"
)
func foo() {
c := time.Tick(5 * time.Second)
for next := range c {
fmt.Println(next)
// No way to cancel or reset the timer
}
}
import (
"fmt"
"time"
)
func foo() {
ticker := time.NewTicker(5 * time.Second)
go func() {
time.Sleep(20 * time.Second)
ticker.Stop()
}()
for next: = range ticker.C {
fmt.Println(next)
// Will only go until the first 20 seconds
}
}