backoff

package
v2.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoff

type Backoff struct {
	Type          BackoffType   `json:"type" yaml:"type" ini:"type"`                               // 递增曲线类型
	InitialSleep  time.Duration `json:"initial_sleep" yaml:"initial_sleep" ini:"initial_sleep"`    // 初始等待时间
	MaxSleep      time.Duration `json:"max_sleep" yaml:"max_sleep" ini:"max_sleep"`                // 最大等待时间
	Step          time.Duration `json:"step" yaml:"step" ini:"step"`                               // 线性递增的步长(仅用于 Linear 和 Step 类型)
	Base          float64       `json:"base" yaml:"base" ini:"base"`                               // 指数递增的基数(仅用于 Exponential 类型)
	StepThreshold int           `json:"step_threshold" yaml:"step_threshold" ini:"step_threshold"` // 分段递增的阈值(仅用于 Step 类型)
	// contains filtered or unexported fields
}

Backoff 封装了递增睡眠时间的逻辑

func NewBackoff

func NewBackoff(backoffType BackoffType, initialSleep, maxSleep time.Duration, options ...any) *Backoff

NewBackoff 创建一个新的 Backoff 实例

func (*Backoff) Next

func (b *Backoff) Next() time.Duration

Next 返回下一次的等待时间,并更新状态

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset 重置 Backoff 状态

type BackoffType

type BackoffType int

BackoffType 定义递增曲线的类型

const (
	Exponential BackoffType = iota // 指数递增
	Linear                         // 线性递增
	Logarithmic                    // 对数递增
	Randomized                     // 随机化递增
	Step                           // 分段递增
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL