...
1 package watch
2
3 import (
4 "time"
5
6 "github.com/segmentio/backo-go"
7 "k8s.io/klog"
8 )
9
10 type ExpBackoff struct {
11 attempt int
12 backo *backo.Backo
13 }
14
15 func NewExpBackoff() *ExpBackoff {
16 return &ExpBackoff{
17 backo: backo.DefaultBacko(),
18 }
19 }
20
21 func (o *ExpBackoff) Delay() time.Duration {
22 duration := o.backo.Duration(o.attempt)
23 klog.V(4).Infof("wait for %v\n", duration)
24 o.attempt++
25 return duration
26 }
27
28 func (o *ExpBackoff) Reset() {
29 o.attempt = 0
30 }
31
View as plain text