Files
kured/pkg/delaytick/delaytick.go
Jean-Philippe Evrard 5d88e6c6db Make lint happier in pkg folder
Without this patch, lint will complain about a few cosmetic details.
2020-11-05 11:01:49 +01:00

23 lines
422 B
Go

package delaytick
import (
"math/rand"
"time"
)
// New ticks regularly after an initial delay randomly distributed between d/2 and d + d/2
func New(s rand.Source, d time.Duration) <-chan time.Time {
c := make(chan time.Time)
go func() {
random := rand.New(s)
time.Sleep(time.Duration(float64(d)/2 + float64(d)*random.Float64()))
c <- time.Now()
for t := range time.Tick(d) {
c <- t
}
}()
return c
}