influxdb/time.go

18 lines
404 B
Go
Raw Normal View History

2013-05-26 21:51:01 +00:00
package raft
import (
"math/rand"
"time"
)
// Waits for a random time between two durations and sends the current time on
// the returned channel.
func afterBetween(min time.Duration, max time.Duration) <-chan time.Time {
rand := rand.New(rand.NewSource(time.Now().UnixNano()))
2013-05-27 00:02:31 +00:00
d, delta := min, (max - min)
2013-05-26 21:51:01 +00:00
if delta > 0 {
d += time.Duration(rand.Int63n(int64(delta)))
}
return time.After(d)
}