Documentation
¶
Overview ¶
Package retry 可取消的重试与轮询原语(stdlib-only):带退避的动作重试 + 到 deadline 为止的条件轮询。收编自消费方三类手写形态——SQLite busy 退避 重试(线性递增)、双副本首启的固定间隔回读、并发败者/终态等待的条件轮询。
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrTimeout = errors.New("retry: 轮询超时")
ErrTimeout Poll 超时(调用方按需区分「条件未达成」与真错误)。
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Attempts 总尝试次数(含首次);<=1 视为 1。
Attempts int
// Delay 退避基数。Linear=false 固定间隔;Linear=true 第 i 次失败后等待 Delay*i。
// Exponential=true 时第 i 次失败后等待 Delay*2^(i-1)(见 Exponential)。
Delay time.Duration
// MaxDelay 单次退避上限(<=0 不限)。
MaxDelay time.Duration
// Linear true=线性递增退避(Delay*i),false=固定间隔。
// 与 Exponential 同时为 true 时 Exponential 优先。
Linear bool
// Exponential true=指数退避 Delay*2^(attempt-1),受 MaxDelay 封顶。
// 外部频控(429/5xx)的标准应对姿势。
Exponential bool
// Jitter 可选抖动:每次退避在计算结果上叠加 [0, Jitter) 随机量。
// 0 = 关闭。用于打散同时失败的重试风暴。
Jitter time.Duration
// Retryable 判定错误是否可重试;nil = 所有错误都重试。
Retryable func(error) bool
}
Config 重试参数。零值 = 只执行一次、不重试。
Click to show internal directories.
Click to hide internal directories.