/usr/share/gocode/src/gopkg.in/retry.v1/exp.go is in golang-gopkg-retry.v1-dev 0.0~git20161025.0.c09f6b8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | package retry // import "gopkg.in/retry.v1"
import (
"time"
)
// Exponential represents an exponential backoff retry strategy.
// To limit the number of attempts or their overall duration, wrap
// this in LimitCount or LimitDuration.
type Exponential struct {
// Initial holds the initial delay.
Initial time.Duration
// Factor holds the factor that the delay time will be multiplied
// by on each iteration.
Factor float64
// MaxDelay holds the maximum delay between the start
// of attempts. If this is zero, there is no maximum delay.
MaxDelay time.Duration
}
type exponentialTimer struct {
strategy Exponential
start time.Time
end time.Time
delay time.Duration
}
// NewTimer implements Strategy.NewTimer.
func (r Exponential) NewTimer(now time.Time) Timer {
return &exponentialTimer{
strategy: r,
start: now,
delay: r.Initial,
}
}
// NextSleep implements Timer.NextSleep.
func (a *exponentialTimer) NextSleep(now time.Time) (time.Duration, bool) {
sleep := a.delay - now.Sub(a.start)
if sleep <= 0 {
sleep = 0
}
// Set the start of the next try.
a.start = now.Add(sleep)
a.delay = time.Duration(float64(a.delay) * a.strategy.Factor)
if a.strategy.MaxDelay > 0 && a.delay > a.strategy.MaxDelay {
a.delay = a.strategy.MaxDelay
}
return sleep, true
}
|