backoff

package
v0.0.0-...-680e691 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Stop = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BackOff

type BackOff interface {
	// return -1 mean stop
	Next() time.Duration
	Reset()
}

BackOff 接口定义

func NewExponential

func NewExponential(opts ...ExponentialOption) BackOff

NewExponential .

type ConstantBackOff

type ConstantBackOff struct {
	Interval time.Duration
}

func NewConstant

func NewConstant(d time.Duration) *ConstantBackOff

func (*ConstantBackOff) Next

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

func (*ConstantBackOff) Reset

func (b *ConstantBackOff) Reset()

type ExponentialBackOff

type ExponentialBackOff struct {
	// contains filtered or unexported fields
}

https://aws.amazon.com/cn/blogs/architecture/exponential-backoff-and-jitter/ https://www.baeldung.com/resilience4j-backoff-jitter https://github.com/grpc/grpc-go/blob/master/internal/backoff/backoff.go https://github.com/jpillora/backoff/blob/master/backoff.go https://github.com/rfyiamcool/backoff

float64(b.Min) * math.Pow(b.Factor, b.Attempts) wait_interval = base * multiplier^n

func (*ExponentialBackOff) Next

func (e *ExponentialBackOff) Next() time.Duration

func (*ExponentialBackOff) Reset

func (e *ExponentialBackOff) Reset()

type ExponentialOption

type ExponentialOption func(b *ExponentialBackOff)

func WithFactor

func WithFactor(v float64) ExponentialOption

func WithJitter

func WithJitter(v bool) ExponentialOption

func WithMax

func WithMax(d time.Duration) ExponentialOption

func WithMin

func WithMin(d time.Duration) ExponentialOption

type StopBackOff

type StopBackOff struct {
}

func (*StopBackOff) Next

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

func (*StopBackOff) Reset

func (b *StopBackOff) Reset()

type ZeroBackOff

type ZeroBackOff struct {
}

func (*ZeroBackOff) Next

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

func (*ZeroBackOff) Reset

func (b *ZeroBackOff) Reset()

Jump to

Keyboard shortcuts

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