Documentation ¶
Index ¶
- Constants
- func After(d time.Duration) <-chan time.Time
- func DecorrelatedJitterDelayHandler(_ int, cap, base, last time.Duration) time.Duration
- func EqualJitterDelayHandler(attempt int, cap, base, _ time.Duration) time.Duration
- func ExponentialDelayHandler(attempt int, cap, base, _ time.Duration) time.Duration
- func FullJitterDelayHandler(attempt int, cap, base, _ time.Duration) time.Duration
- func NoneBackOffDelayHandler(_ int, cap, base, _ time.Duration) time.Duration
- type BackOff
- type Cost
- type Delay
- type DelayHandler
- type DelayHandlerFunc
- type EmptyExponentialBackOffOption
- type ExponentialBackOff
- func (o *ExponentialBackOff) ApplyOptions(options ...ExponentialBackOffOption) *ExponentialBackOff
- func (o *ExponentialBackOff) GetCurrentInterval() time.Duration
- func (o *ExponentialBackOff) GetElapsedDuration() time.Duration
- func (o *ExponentialBackOff) GetInitialInterval() time.Duration
- func (o *ExponentialBackOff) GetMaxElapsedDuration() time.Duration
- func (o *ExponentialBackOff) GetMaxInterval() time.Duration
- func (o *ExponentialBackOff) GetMultiplier() float64
- func (o *ExponentialBackOff) GetRandomValueFromInterval(randomizationFactor float64, random float64, currentInterval time.Duration) time.Duration
- func (o *ExponentialBackOff) GetRandomizationFactor() float64
- func (o *ExponentialBackOff) NextBackOff() time.Duration
- func (o *ExponentialBackOff) Reset()
- type ExponentialBackOffOption
- func WithExponentialBackOffOptionInitialInterval(duration time.Duration) ExponentialBackOffOption
- func WithExponentialBackOffOptionMaxElapsedDuration(duration time.Duration) ExponentialBackOffOption
- func WithExponentialBackOffOptionMaxInterval(maxInterval time.Duration) ExponentialBackOffOption
- func WithExponentialBackOffOptionMultiplier(multiplier float64) ExponentialBackOffOption
- func WithExponentialBackOffOptionRandomizationFactor(factor float64) ExponentialBackOffOption
- type ExponentialBackOffOptionFunc
- type StopBackOff
- type Timer
- type ZeroBackOff
Constants ¶
const ( // The default initial interval value (0.5 seconds). DefaultInitialInterval = 500 * time.Millisecond // The default randomization factor (0.5 which results in a random period ranging between 50% // below and 50% above the retry interval). DefaultRandomizationFactor = 0.5 // The default multiplier value (1.5 which is 50% increase per back off). DefaultMultiplier = 1.5 // The default maximum back off time (1 minute). DefaultMaxInterval = time.Minute // The default maximum elapsed time (15 minutes). DefaultMaxElapsedDuration = 15 * time.Minute // Indicates that no more retries should be made for use in {@link #NextBackOff()}. StopDuration = time.Duration(-1) )
const DefaultBaseDuration = 5 * time.Millisecond
const DefaultMaxDuration = 1 * time.Second
const InfDuration = time.Duration(1<<63 - 1)
InfDuration is the duration returned by Delay when a Reservation is not OK.
const ZeroDuration = 0
Variables ¶
This section is empty.
Functions ¶
func DecorrelatedJitterDelayHandler ¶ added in v0.0.87
exponentially backed-off with decorrelated jitter sleep = min(cap, random_between(base, sleep * 3))
func EqualJitterDelayHandler ¶ added in v0.0.87
exponentially backed-off with equal jitter temp = min(cap, base * 2 ** attempt) sleep = temp/2 + random_between(temp/2, min(cap, base * 2 ** attempt))
func ExponentialDelayHandler ¶ added in v0.0.87
exponentially backed-off sleep = min(cap, base * 2 ** attempt)
func FullJitterDelayHandler ¶ added in v0.0.87
exponentially backed-off with full jitter sleep = random_between(0, min(cap, base * 2 ** attempt))
Types ¶
type BackOff ¶ added in v0.0.87
type BackOff interface { // Reset to initial state. Reset() // Gets duration to wait before retrying the operation or {@link #STOP} to // indicate that no retries should be made. // Example usage: // var backOffDuration = backoff.NextBackOff(); // if (backOffDuration == Backoff.STOP) { // // do not retry operation // } else { // // sleep for backOffDuration milliseconds and retry operation // } NextBackOff() time.Duration }
Code borrowed from https://github.com/googleapis/google-http-java-client/blob/master/google-http-client/ src/main/java/com/google/api/client/util/BackOff.java
type Delay ¶
type Delay struct { Base time.Duration Cap time.Duration Handler DelayHandler // contains filtered or unexported fields }
func NewDefaultExponentialDelay ¶ added in v0.0.87
func NewDefaultExponentialDelay() *Delay
func (*Delay) NextBackOff ¶ added in v0.0.87
Gets duration to wait before retrying the operation or {@link #STOP} to indicate that no retries should be made. Example usage: var backOffMillis = backoff.NextBackOff();
if (backOffMillis == Backoff.STOP) { // do not retry operation } else {
// sleep for backOffMillis milliseconds and retry operation }
type DelayHandler ¶ added in v0.0.87
type DelayHandlerFunc ¶ added in v0.0.87
The HandlerFunc type is an adapter to allow the use of ordinary functions as HTTP handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.
type EmptyExponentialBackOffOption ¶ added in v0.0.93
type EmptyExponentialBackOffOption struct{}
EmptyExponentialBackOffOption does not alter the configuration. It can be embedded in another structure to build custom options.
This API is EXPERIMENTAL.
type ExponentialBackOff ¶ added in v0.0.87
type ExponentialBackOff struct {
// contains filtered or unexported fields
}
Code borrowed from https://github.com/googleapis/google-http-java-client/blob/master/google-http-client/ src/main/java/com/google/api/client/util/ExponentialBackOff.java
func NewExponentialBackOff ¶ added in v0.0.87
func NewExponentialBackOff(opts ...ExponentialBackOffOption) *ExponentialBackOff
func (*ExponentialBackOff) ApplyOptions ¶ added in v0.0.93
func (o *ExponentialBackOff) ApplyOptions(options ...ExponentialBackOffOption) *ExponentialBackOff
func (*ExponentialBackOff) GetCurrentInterval ¶ added in v0.0.87
func (o *ExponentialBackOff) GetCurrentInterval() time.Duration
Returns the current retry interval.
func (*ExponentialBackOff) GetElapsedDuration ¶ added in v0.0.87
func (o *ExponentialBackOff) GetElapsedDuration() time.Duration
Returns the elapsed time since an {@link ExponentialBackOff} instance is created and is reset when {@link #reset()} is called. The elapsed time is computed using {@link System#nanoTime()}.
func (*ExponentialBackOff) GetInitialInterval ¶ added in v0.0.87
func (o *ExponentialBackOff) GetInitialInterval() time.Duration
Returns the initial retry interval.
func (*ExponentialBackOff) GetMaxElapsedDuration ¶ added in v0.0.87
func (o *ExponentialBackOff) GetMaxElapsedDuration() time.Duration
Returns the maximum elapsed time. If the time elapsed since an {@link ExponentialBackOff} instance is created goes past the max_elapsed_time then the method {@link #NextBackOff()} starts returning STOP. The elapsed time can be reset by calling
func (*ExponentialBackOff) GetMaxInterval ¶ added in v0.0.87
func (o *ExponentialBackOff) GetMaxInterval() time.Duration
Returns the maximum value of the back off period. Once the current interval reaches this value it stops increasing.
func (*ExponentialBackOff) GetMultiplier ¶ added in v0.0.87
func (o *ExponentialBackOff) GetMultiplier() float64
Returns the value to multiply the current interval with for each retry attempt.
func (*ExponentialBackOff) GetRandomValueFromInterval ¶ added in v0.0.87
func (o *ExponentialBackOff) GetRandomValueFromInterval( randomizationFactor float64, random float64, currentInterval time.Duration) time.Duration
*
- Returns a random value from the interval [randomizationFactor * currentInterval,
- randomizationFactor * currentInterval].
func (*ExponentialBackOff) GetRandomizationFactor ¶ added in v0.0.87
func (o *ExponentialBackOff) GetRandomizationFactor() float64
Returns the randomization factor to use for creating a range around the retry interval. A randomization factor of 0.5 results in a random period ranging between 50% below and 50% above the retry interval.
func (*ExponentialBackOff) NextBackOff ¶ added in v0.0.87
func (o *ExponentialBackOff) NextBackOff() time.Duration
*
- {@inheritDoc} *
- <p>This method calculates the next back off interval using the formula: randomized_interval =
- retry_interval +/- (randomization_factor * retry_interval) *
- <p>Subclasses may override if a different algorithm is required.
func (*ExponentialBackOff) Reset ¶ added in v0.0.87
func (o *ExponentialBackOff) Reset()
Sets the interval back to the initial retry interval and restarts the timer.
type ExponentialBackOffOption ¶ added in v0.0.93
type ExponentialBackOffOption interface {
// contains filtered or unexported methods
}
A ExponentialBackOffOption sets options.
func WithExponentialBackOffOptionInitialInterval ¶ added in v0.0.93
func WithExponentialBackOffOptionInitialInterval(duration time.Duration) ExponentialBackOffOption
func WithExponentialBackOffOptionMaxElapsedDuration ¶ added in v0.0.93
func WithExponentialBackOffOptionMaxElapsedDuration(duration time.Duration) ExponentialBackOffOption
func WithExponentialBackOffOptionMaxInterval ¶ added in v0.0.93
func WithExponentialBackOffOptionMaxInterval(maxInterval time.Duration) ExponentialBackOffOption
func WithExponentialBackOffOptionMultiplier ¶ added in v0.0.93
func WithExponentialBackOffOptionMultiplier(multiplier float64) ExponentialBackOffOption
func WithExponentialBackOffOptionRandomizationFactor ¶ added in v0.0.93
func WithExponentialBackOffOptionRandomizationFactor(factor float64) ExponentialBackOffOption
type ExponentialBackOffOptionFunc ¶ added in v0.0.93
type ExponentialBackOffOptionFunc func(*ExponentialBackOff)
ExponentialBackOffOptionFunc wraps a function that modifies ExponentialBackOff into an implementation of the ExponentialBackOffOption interface.
type StopBackOff ¶ added in v0.0.87
type StopBackOff struct { }
func (*StopBackOff) NextBackOff ¶ added in v0.0.87
func (o *StopBackOff) NextBackOff() time.Duration
func (*StopBackOff) Reset ¶ added in v0.0.87
func (o *StopBackOff) Reset()
type Timer ¶
https://github.com/golang/go/issues/27169 Timer to fix time: Timer.Stop documentation example easily leads to deadlocks
func (*Timer) Reset ¶
Reset changes the timer to expire after duration d. Reset can be invoked anytime, which enhances std time.Reset Reset == std [Stop + drain + Reset] It returns true if the timer had been active, false if the timer had expired or been stopped.
func (*Timer) Stop ¶
Stop prevents the Timer from firing, with the channel drained. Stop ensures the channel is empty after a call to Stop. Stop == std [Stop + drain] It returns true if the call stops the timer, false if the timer has already expired or been stopped. Stop does not close the channel, to prevent a read from the channel succeeding incorrectly.
type ZeroBackOff ¶ added in v0.0.87
type ZeroBackOff struct { }
func (*ZeroBackOff) NextBackOff ¶ added in v0.0.87
func (o *ZeroBackOff) NextBackOff() time.Duration
func (*ZeroBackOff) Reset ¶ added in v0.0.87
func (o *ZeroBackOff) Reset()