...
1 package backoff
2
3 import "time"
4
5
12 func WithMaxRetries(b BackOff, max uint64) BackOff {
13 return &backOffTries{delegate: b, maxTries: max}
14 }
15
16 type backOffTries struct {
17 delegate BackOff
18 maxTries uint64
19 numTries uint64
20 }
21
22 func (b *backOffTries) NextBackOff() time.Duration {
23 if b.maxTries == 0 {
24 return Stop
25 }
26 if b.maxTries > 0 {
27 if b.maxTries <= b.numTries {
28 return Stop
29 }
30 b.numTries++
31 }
32 return b.delegate.NextBackOff()
33 }
34
35 func (b *backOffTries) Reset() {
36 b.numTries = 0
37 b.delegate.Reset()
38 }
39
View as plain text