MCPcopy Create free account
hub / github.com/imroc/req / backoffInterval

Function backoffInterval

retry.go:24–33  ·  view source on GitHub ↗
(min, max time.Duration)

Source from the content-addressed store, hash-verified

22type GetRetryIntervalFunc func(resp *Response, attempt int) time.Duration
23
24func backoffInterval(min, max time.Duration) GetRetryIntervalFunc {
25 base := float64(min)
26 capLevel := float64(max)
27 return func(resp *Response, attempt int) time.Duration {
28 temp := math.Min(capLevel, base*math.Exp2(float64(attempt)))
29 halfTemp := int64(temp / 2)
30 sleep := halfTemp + rand.Int63n(halfTemp)
31 return time.Duration(sleep)
32 }
33}
34
35func newDefaultRetryOption() *retryOption {
36 return &retryOption{

Callers 2

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…