github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/utils/retry/backoff.go (about) 1 package retry 2 3 import ( 4 "time" 5 6 "github.com/jxskiss/gopkg/v2/internal" 7 ) 8 9 func addJitter(duration time.Duration, jitter float64) time.Duration { 10 return internal.AddJitter(duration, jitter) 11 } 12 13 type strategy func(time.Duration) time.Duration 14 15 func exp(sleep time.Duration) time.Duration { 16 return sleep * 2 17 } 18 19 func constant(sleep time.Duration) time.Duration { 20 return sleep 21 } 22 23 type linear struct { 24 step time.Duration 25 } 26 27 func (l linear) next(sleep time.Duration) time.Duration { 28 return sleep + l.step 29 }