github.com/searKing/golang/go@v1.2.117/time/exponentialbackoff.options.go (about) 1 // Copyright 2020 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package time 6 7 import "time" 8 9 func WithExponentialBackOffOptionInitialInterval(duration time.Duration) ExponentialBackOffOption { 10 return ExponentialBackOffOptionFunc(func(o *ExponentialBackOff) { 11 o.initialInterval = duration 12 }) 13 } 14 15 func WithExponentialBackOffOptionRandomizationFactor(factor float64) ExponentialBackOffOption { 16 return ExponentialBackOffOptionFunc(func(o *ExponentialBackOff) { 17 o.randomizationFactor = factor 18 }) 19 } 20 21 func WithExponentialBackOffOptionMultiplier(multiplier float64) ExponentialBackOffOption { 22 return ExponentialBackOffOptionFunc(func(o *ExponentialBackOff) { 23 o.multiplier = multiplier 24 }) 25 } 26 27 func WithExponentialBackOffOptionMaxInterval(maxInterval time.Duration) ExponentialBackOffOption { 28 return ExponentialBackOffOptionFunc(func(o *ExponentialBackOff) { 29 o.maxInterval = maxInterval 30 }) 31 } 32 33 func WithExponentialBackOffOptionMaxElapsedDuration(duration time.Duration) ExponentialBackOffOption { 34 return ExponentialBackOffOptionFunc(func(o *ExponentialBackOff) { 35 o.maxElapsedDuration = duration 36 }) 37 } 38 39 func WithExponentialBackOffOptionMaxElapsedCount(count int) ExponentialBackOffOption { 40 return ExponentialBackOffOptionFunc(func(o *ExponentialBackOff) { 41 o.maxElapsedCount = count 42 }) 43 } 44 45 func WithExponentialBackOffOptionNoLimit() ExponentialBackOffOption { 46 return ExponentialBackOffOptionFunc(func(o *ExponentialBackOff) { 47 o.initialInterval = DefaultInitialInterval 48 o.randomizationFactor = DefaultRandomizationFactor 49 o.multiplier = DefaultMultiplier 50 o.maxInterval = -1 51 o.maxElapsedDuration = -1 52 o.maxElapsedCount = -1 53 }) 54 } 55 56 func WithExponentialBackOffOptionGRPC() ExponentialBackOffOption { 57 return ExponentialBackOffOptionFunc(func(o *ExponentialBackOff) { 58 o.initialInterval = 1.0 * time.Second 59 o.randomizationFactor = 0.2 60 o.multiplier = 1.6 61 o.maxInterval = 120 * time.Second 62 o.maxElapsedDuration = -1 63 o.maxElapsedCount = -1 64 }) 65 }