Documentation ¶
Index ¶
- Variables
- type BackoffHandler
- func (b *BackoffHandler) Backoff(ctx context.Context) bool
- func (b *BackoffHandler) BackoffTimer() <-chan time.Time
- func (b BackoffHandler) GetBaseTime() time.Duration
- func (b BackoffHandler) GetMaxBackoffDuration(ctx context.Context) (time.Duration, bool)
- func (b *BackoffHandler) ReachedMaxRetries() bool
- func (b *BackoffHandler) ResetNow()
- func (b *BackoffHandler) Retries() int
- func (b *BackoffHandler) SetGracePeriod() time.Duration
Constants ¶
This section is empty.
Variables ¶
var Clock = clock{ Now: time.Now, After: time.After, }
Functions ¶
This section is empty.
Types ¶
type BackoffHandler ¶
type BackoffHandler struct { // MaxRetries sets the maximum number of retries to perform. The default value // of 0 disables retry completely. MaxRetries uint // RetryForever caps the exponential backoff period according to MaxRetries // but allows you to retry indefinitely. RetryForever bool // BaseTime sets the initial backoff period. BaseTime time.Duration // contains filtered or unexported fields }
BackoffHandler manages exponential backoff and limits the maximum number of retries. The base time period is 1 second, doubling with each retry. After initial success, a grace period can be set to reset the backoff timer if a connection is maintained successfully for a long enough period. The base grace period is 2 seconds, doubling with each retry.
func (*BackoffHandler) Backoff ¶
func (b *BackoffHandler) Backoff(ctx context.Context) bool
Backoff is used to wait according to exponential backoff. Returns false if the maximum number of retries have been used or if the underlying context has been cancelled.
func (*BackoffHandler) BackoffTimer ¶
func (b *BackoffHandler) BackoffTimer() <-chan time.Time
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.
func (BackoffHandler) GetBaseTime ¶
func (b BackoffHandler) GetBaseTime() time.Duration
func (BackoffHandler) GetMaxBackoffDuration ¶
func (*BackoffHandler) ReachedMaxRetries ¶
func (b *BackoffHandler) ReachedMaxRetries() bool
func (*BackoffHandler) ResetNow ¶
func (b *BackoffHandler) ResetNow()
func (*BackoffHandler) Retries ¶
func (b *BackoffHandler) Retries() int
Retries returns the number of retries consumed so far.
func (*BackoffHandler) SetGracePeriod ¶
func (b *BackoffHandler) SetGracePeriod() time.Duration
Sets a grace period within which the the backoff timer is maintained. After the grace period expires, the number of retries & backoff duration is reset.