Documentation
¶
Index ¶
- func Inject(ctx context.Context, backoff BackoffFunc) context.Context
- type BackoffFunc
- func Constant(delta time.Duration) BackoffFunc
- func Context() BackoffFunc
- func Exponential(delta time.Duration) BackoffFunc
- func Exponential2(delta time.Duration) BackoffFunc
- func Fibonacci(delta time.Duration) BackoffFunc
- func JitterUp(backoff BackoffFunc, jitter float64) BackoffFunc
- func Linear(delta time.Duration) BackoffFunc
- func Random(alpha, beta time.Duration) BackoffFunc
- func Zero() BackoffFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BackoffFunc ¶
BackoffFunc denotes a family of functions that control the backoff duration between call retries.
They are called with an identifier of the attempt, and should return a time the system client should hold off for. If the time returned is longer than the `context.Context.Deadline` of the request the deadline of the request takes precedence and the wait will be interrupted before proceeding with the next iteration. The context can be used to extract context values.
func Constant ¶
func Constant(delta time.Duration) BackoffFunc
Constant it waits for a fixed period of time between calls.
func Context ¶
func Context() BackoffFunc
Context 从给定的上下文中获取一个回退函数,如果存在则调用它并返回回退时间;否则返回0。主要用于动态设置重试间的延迟。
func Exponential ¶
func Exponential(delta time.Duration) BackoffFunc
Exponential it waits for "delta * e^attempts" time between calls.
func Exponential2 ¶
func Exponential2(delta time.Duration) BackoffFunc
Exponential2 it waits for "delta * 2^attempts" time between calls.
func Fibonacci ¶
func Fibonacci(delta time.Duration) BackoffFunc
Fibonacci it waits for "delta * fibonacci(attempt)" time between calls.
func JitterUp ¶
func JitterUp(backoff BackoffFunc, jitter float64) BackoffFunc
JitterUp adds random jitter to the interval.
This adds or subtracts time from the interval within a given jitter fraction. For example for 10s and jitter 0.1, it will return a time within [9s, 11s])
func Linear ¶
func Linear(delta time.Duration) BackoffFunc
Linear it waits for "delta * attempt" time between calls.
func Random ¶
func Random(alpha, beta time.Duration) BackoffFunc
Random generates a function that waits for a random time in the range [alpha, beta) between calls.