Ensure the same duration is never computed

This commit is contained in:
Evan Borgstrom 2019-09-26 10:14:32 +08:00
parent dccb0d859c
commit d4259e493a
1 changed files with 1 additions and 2 deletions

View File

@ -27,8 +27,7 @@ type Backoff struct {
// Duration returns the duration for the current attempt before incrementing // Duration returns the duration for the current attempt before incrementing
// the attempt counter. See ForAttempt. // the attempt counter. See ForAttempt.
func (b *Backoff) Duration() time.Duration { func (b *Backoff) Duration() time.Duration {
d := b.ForAttempt(float64(atomic.LoadUint64(&b.attempt))) d := b.ForAttempt(float64(atomic.AddUint64(&b.attempt, 1) - 1))
atomic.AddUint64(&b.attempt, 1)
return d return d
} }