BackoffTimer returns a channel that sends the current time when the exponential backoff timeout expires. Returns nil if the maximum number of retries have been used.
()
| 68 | // BackoffTimer returns a channel that sends the current time when the exponential backoff timeout expires. |
| 69 | // Returns nil if the maximum number of retries have been used. |
| 70 | func (b *BackoffHandler) BackoffTimer() <-chan time.Time { |
| 71 | if !b.resetDeadline.IsZero() && b.Clock.Now().After(b.resetDeadline) { |
| 72 | b.retries = 0 |
| 73 | b.resetDeadline = time.Time{} |
| 74 | } |
| 75 | if b.retries >= b.maxRetries { |
| 76 | if !b.retryForever { |
| 77 | return nil |
| 78 | } |
| 79 | } else { |
| 80 | b.retries++ |
| 81 | } |
| 82 | maxTimeToWait := b.GetBaseTime() * (1 << b.retries) |
| 83 | timeToWait := time.Duration(rand.Int63n(maxTimeToWait.Nanoseconds())) // #nosec G404 |
| 84 | return b.Clock.After(timeToWait) |
| 85 | } |
| 86 | |
| 87 | // Backoff is used to wait according to exponential backoff. Returns false if the |
| 88 | // maximum number of retries have been used or if the underlying context has been cancelled. |