@@ -4,20 +4,11 @@ import (
44 "math"
55 "time"
66
7- "github.com/jonboulle/clockwork"
8-
97 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xrand"
108)
119
1210// Backoff is the interface that contains logic of delaying operation retry.
1311type Backoff interface {
14- // Wait maps index of the retry to a channel which fulfillment means that
15- // Delay is over.
16- //
17- // Note that retry index begins from 0 and 0-th index means that it is the
18- // first retry attempt after an initial error.
19- Wait (n int ) <- chan time.Time
20-
2112 // Delay returns mapping of i to Delay.
2213 Delay (i int ) time.Duration
2314}
3930 )
4031)
4132
33+ var _ Backoff = (* logBackoff )(nil )
34+
4235// logBackoff contains logarithmic Backoff policy.
4336type logBackoff struct {
4437 // slotDuration is a size of a single time slot used in Backoff Delay
@@ -59,8 +52,6 @@ type logBackoff struct {
5952 // duration D; and R is a random sized part from [0,(D - F)].
6053 jitterLimit float64
6154
62- clock clockwork.Clock
63-
6455 // generator of jitter
6556 r xrand.Rand
6657}
@@ -85,12 +76,6 @@ func WithJitterLimit(jitterLimit float64) option {
8576 }
8677}
8778
88- func WithClock (clock clockwork.Clock ) option {
89- return func (b * logBackoff ) {
90- b .clock = clock
91- }
92- }
93-
9479func WithSeed (seed int64 ) option {
9580 return func (b * logBackoff ) {
9681 b .r = xrand .New (xrand .WithLock (), xrand .WithSeed (seed ))
@@ -99,8 +84,7 @@ func WithSeed(seed int64) option {
9984
10085func New (opts ... option ) logBackoff {
10186 b := logBackoff {
102- r : xrand .New (xrand .WithLock ()),
103- clock : clockwork .NewRealClock (),
87+ r : xrand .New (xrand .WithLock ()),
10488 }
10589 for _ , o := range opts {
10690 if o != nil {
@@ -110,11 +94,6 @@ func New(opts ...option) logBackoff {
11094 return b
11195}
11296
113- // Wait implements Backoff interface.
114- func (b logBackoff ) Wait (n int ) <- chan time.Time {
115- return b .clock .After (b .Delay (n ))
116- }
117-
11897// Delay returns mapping of i to Delay.
11998func (b logBackoff ) Delay (i int ) time.Duration {
12099 s := b .slotDuration
0 commit comments