Skip to content

Commit

Permalink
rename backoff
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <[email protected]>
  • Loading branch information
HuSharp committed Aug 29, 2023
1 parent dda1bb4 commit 39b2043
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions client/retry/backoff.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import (

// BackOffer is a backoff policy for retrying operations.
type BackOffer struct {
maxBackoff time.Duration
nextBackoff time.Duration
initialBackoff time.Duration
max time.Duration
next time.Duration
base time.Duration
}

// WithBackoff is a helper function to add backoff.
Expand All @@ -50,11 +50,11 @@ func WithBackoff(
}

// InitialBackOffer make the initial state for retrying.
func InitialBackOffer(initialBackoff, maxBackoff time.Duration) BackOffer {
func InitialBackOffer(base, max time.Duration) BackOffer {
return BackOffer{
maxBackoff: maxBackoff,
initialBackoff: initialBackoff,
nextBackoff: initialBackoff,
max: max,
base: base,
next: base,
}
}

Expand All @@ -63,19 +63,19 @@ func (rs *BackOffer) NextBackoff() time.Duration {
return rs.exponentialBackoff()
}

// exponentialBackoff Get the exponential backoff duration.
// exponentialBackoff returns the exponential backoff duration.
func (rs *BackOffer) exponentialBackoff() time.Duration {
backoff := rs.nextBackoff
rs.nextBackoff *= 2
if rs.nextBackoff > rs.maxBackoff {
rs.nextBackoff = rs.maxBackoff
backoffInterval := rs.next
rs.next *= 2
if rs.next > rs.max {
rs.next = rs.max
}
return backoff
return backoffInterval
}

// ResetBackoff reset the backoff to initial state.
// ResetBackoff resets the backoff to initial state.
func (rs *BackOffer) ResetBackoff() {
rs.nextBackoff = rs.initialBackoff
rs.next = rs.base
}

// Only used for test.
Expand Down

0 comments on commit 39b2043

Please sign in to comment.