(retry int, minBackoff, maxBackoff time.Duration)
| 6 | ) |
| 7 | |
| 8 | func RetryBackoff(retry int, minBackoff, maxBackoff time.Duration) time.Duration { |
| 9 | if retry < 0 { |
| 10 | panic("not reached") |
| 11 | } |
| 12 | if minBackoff == 0 { |
| 13 | return 0 |
| 14 | } |
| 15 | |
| 16 | d := minBackoff << uint(retry) |
| 17 | if d < minBackoff { |
| 18 | return maxBackoff |
| 19 | } |
| 20 | |
| 21 | d = minBackoff + time.Duration(rand.Int63n(int64(d))) |
| 22 | |
| 23 | if d > maxBackoff || d < minBackoff { |
| 24 | d = maxBackoff |
| 25 | } |
| 26 | |
| 27 | return d |
| 28 | } |
no outgoing calls