retry

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: BSD-2-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Call

func Call[T any](r Retryer, f func() (T, error)) (T, error)

Call run function with retry. If function return an non-nil error, will retry if not exceed MaxTimes.

Types

type Backoff

type Backoff func(times int) time.Duration

Backoff is a function that provides delay time for retries. A zero or negative value no delay time between retries. The times start from 1, means the first retry

func ExponentialBackoff

func ExponentialBackoff(initialDelay time.Duration) Backoff

ExponentialBackoff provides binary exponential backoff algorithm. Param initialDelay: the intial delay time for first retry.

func FixedBackoff

func FixedBackoff(delay time.Duration) Backoff

FixedBackoff provides fixed-delay backoff algorithm. Param delay: the delay time for retries.

type Retryer

type Retryer struct {
	MaxTimes int     // max retry times. A zero or negetive value imply no retries
	Backoff  Backoff // Backoff return delay time for retries. A nil value imply no Backoff
	Scatter  Scatter // Scatter scatter the delay time. A nil value imply no Scatter
}

Retryer for retry call a function. This can be reused.

func (Retryer) Run

func (r Retryer) Run(f func() error) error

Run run function with retry. If function return an non-nil error, will retry if not exceed MaxTimes.

type Scatter

type Scatter func(delay time.Duration) time.Duration

Scatter is a function that distribute the delay to a range of time

func EvenScatter

func EvenScatter(factor float64) Scatter

EvenScatter return a Scatter fucntion that distribute dealy time to range [delay*(1-factor), delay*(1+factor)) The factor shoud in range [0, 1], otherwise will panics.

Jump to

Keyboard shortcuts

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