Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cenkalti/backoff
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v4.0.0
Choose a base ref
...
head repository: cenkalti/backoff
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v4.0.1
Choose a head ref
  • 2 commits
  • 3 files changed
  • 2 contributors

Commits on Feb 18, 2020

  1. Copy the full SHA
    e13aad9 View commit details

Commits on Apr 3, 2020

  1. Fix crash if nil passed to NewTickerWithTimer

    Doc for function says that passing nil for the timer argument should
    cause the default system timer to be used.  Ensure that that timer is
    actually assigned.
    gwatts authored and cenkalti committed Apr 3, 2020
    Copy the full SHA
    78afdac View commit details
Showing with 11 additions and 1 deletion.
  1. +1 −1 exponential.go
  2. +3 −0 ticker.go
  3. +7 −0 ticker_test.go
2 changes: 1 addition & 1 deletion exponential.go
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@ func (b *ExponentialBackOff) incrementCurrentInterval() {
}

// Returns a random value from the following interval:
// [randomizationFactor * currentInterval, randomizationFactor * currentInterval].
// [currentInterval - randomizationFactor * currentInterval, currentInterval + randomizationFactor * currentInterval].
func getRandomValueFromInterval(randomizationFactor, random float64, currentInterval time.Duration) time.Duration {
var delta = randomizationFactor * float64(currentInterval)
var minInterval = float64(currentInterval) - delta
3 changes: 3 additions & 0 deletions ticker.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,9 @@ func NewTicker(b BackOff) *Ticker {
// NewTickerWithTimer returns a new Ticker with a custom timer.
// A default timer that uses system timer is used when nil is passed.
func NewTickerWithTimer(b BackOff, timer Timer) *Ticker {
if timer == nil {
timer = &defaultTimer{}
}
c := make(chan time.Time)
t := &Ticker{
C: c,
7 changes: 7 additions & 0 deletions ticker_test.go
Original file line number Diff line number Diff line change
@@ -87,3 +87,10 @@ func TestTickerContext(t *testing.T) {
t.Errorf("invalid number of retries: %d", i)
}
}

func TestTickerDefaultTimer(t *testing.T) {
b := NewExponentialBackOff()
ticker := NewTickerWithTimer(b, nil)
// ensure a timer was actually assigned, instead of remaining as nil.
<-ticker.C
}