Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Dec 13, 2024
1 parent 84a3a2c commit 6c819bc
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/backoff/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ type durationCounter struct {
calcNext func(count int, baseDuration time.Duration) time.Duration
}

// Next increments the count and returns the base interval multiplied by the count.
// If the result is greater than the maxDuration, maxDuration is returned.
func (dc *durationCounter) Next() time.Duration {
dc.count++
interval := dc.calcNext(dc.count, dc.baseInterval)
Expand All @@ -19,10 +21,14 @@ func (dc *durationCounter) Next() time.Duration {
return interval
}

// Reset resets the count to 0.
func (dc *durationCounter) Reset() {
dc.count = 0
}

// NewMultiplicativeDurationCounter creates a new durationCounter that multiplies the base interval by the count.
// Count is incremented each time Next() is called and returns the base interval multiplied by the count.
// If the result is greater than the maxDuration, maxDuration is returned.
func NewMultiplicativeDurationCounter(baseDuration, maxDuration time.Duration) *durationCounter {
return &durationCounter{
baseInterval: baseDuration,
Expand Down

0 comments on commit 6c819bc

Please sign in to comment.