Documentation ¶
Index ¶
- Constants
- func After(d time.Duration) <-chan time.Time
- func BackoffUntil(ctx context.Context, f func(ctx context.Context), backoff BackOff, ...)
- 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 Forever(f func(), period time.Duration)
- func FullJitterDelayHandler(attempt int, cap, base, _ time.Duration) time.Duration
- func Jitter(duration time.Duration, maxFactor float64) time.Duration
- func JitterUntil(ctx context.Context, f func(ctx context.Context), sliding bool, ...)
- func NonSlidingUntil(ctx context.Context, f func(ctx context.Context), period time.Duration)
- func NoneBackOffDelayHandler(_ int, cap, base, _ time.Duration) time.Duration
- func Until(ctx context.Context, f func(ctx context.Context), period 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, currentInterval time.Duration) time.Duration
- func (o *ExponentialBackOff) GetRandomizationFactor() float64
- func (o *ExponentialBackOff) NextBackOff() (backoff time.Duration, ok bool)
- 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 )
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 BackoffUntil ¶ added in v0.0.95
BackoffUntil loops until context is done, run f every duration given by BackoffManager.
If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f.
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 Forever ¶ added in v0.0.95
Forever calls f every period for ever.
Forever is syntactic sugar on top of Until.
func FullJitterDelayHandler ¶ added in v0.0.87
exponentially backed-off with full jitter sleep = random_between(0, min(cap, base * 2 ** attempt))
func Jitter ¶ added in v0.0.95
Jitter returns a time.Duration between [duration - maxFactor*duration, duration + maxFactor*duration].
This allows clients to avoid converging on periodic behavior.
func JitterUntil ¶ added in v0.0.95
func JitterUntil(ctx context.Context, f func(ctx context.Context), sliding bool, opts ...ExponentialBackOffOption)
JitterUntil loops until context is done, running f every period.
peroid set by WithExponentialBackOffOptionInitialInterval jitterFactor set by WithExponentialBackOffOptionRandomizationFactor If jitterFactor is positive, the period is jittered before every run of f. If jitterFactor is not positive, the period is unchanged and not jittered.
If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f.
Cancel context to stop. f may not be invoked if context is already expired.
func NonSlidingUntil ¶ added in v0.0.95
NonSlidingUntil loops until context is done, running f every period.
NonSlidingUntil is syntactic sugar on top of JitterUntil with zero jitter factor, with sliding = false (meaning the timer for period starts at the same time as the function starts).
func NoneBackOffDelayHandler ¶ added in v0.0.87
none backed-off sleep = min(cap, base)
Types ¶
type BackOff ¶ added in v0.0.87
type BackOff interface { // Reset to initial state. Reset() // Gets duration to wait before retrying the operation to // indicate that no retries should be made. // ok indicates that no more retries should be made. // Example usage: // var backOffDuration, ok = backoff.NextBackOff(); // if (!ok) { // // do not retry operation // } else { // // sleep for backOffDuration milliseconds and retry operation // } NextBackOff() (backoff time.Duration, ok bool) }
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.
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, 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() (backoff time.Duration, ok bool)
*
- {@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() (backoff time.Duration, ok bool)
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() (backoff time.Duration, ok bool)
func (*ZeroBackOff) Reset ¶ added in v0.0.87
func (o *ZeroBackOff) Reset()