Update clocksmith

This commit is contained in:
Frank Denis 2018-03-07 18:51:55 +01:00
parent 817f2ff560
commit ff81344aa8
2 changed files with 6 additions and 3 deletions

2
Gopkg.lock generated
View file

@ -98,7 +98,7 @@
branch = "master"
name = "github.com/jedisct1/go-clocksmith"
packages = ["."]
revision = "cd58e2ceb29bcb6568281e33a1166f55d2d80188"
revision = "37ddc416ad55843f387500810537f09f0c8d2cf0"
[[projects]]
branch = "master"

View file

@ -14,10 +14,13 @@ func SleepWithGranularity(duration time.Duration, granularity time.Duration) {
time.Sleep(duration)
return
}
now := time.Now()
start := time.Now().Unix()
for {
time.Sleep(granularity)
if elapsed := time.Since(now); elapsed > duration-granularity {
elapsed := time.Duration(time.Now().Unix()-start) * time.Second
if elapsed < 0 || elapsed > duration {
break
} else if elapsed > duration-granularity {
time.Sleep(duration - elapsed)
break
}