backoff

package
v2.11.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: Apache-2.0 Imports: 2 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// Default value to use for number of iterations: infinite
	DefaultMaxIterations uint64 = 0
	// Default value to use for maximum iteration time
	DefaultMaxIterationTime = 60 * time.Second
	// Default value to use for maximum execution time: infinite
	DefaultMaxTotalTime time.Duration = 0
	// Default value to use for initial iteration time
	DefaultMinIterationTime = 100 * time.Millisecond
	// Default multiplier to apply to iteration time after each iteration
	DefaultMultipler float64 = 1.5
)

Variables

This section is empty.

Functions

func Retry

func Retry(f Retryable) error

Retry is a convenience wrapper to execute the retry with default values (see exported constants)

Types

type Backoff

type Backoff struct {
	MaxIterations    uint64
	MaxIterationTime time.Duration
	MaxTotalTime     time.Duration
	MinIterationTime time.Duration
	Multiplier       float64
}

Backoff holds the configuration for backoff function retries

func NewBackoff

func NewBackoff() *Backoff

NewBackoff creates a new Backoff configuration with default values (see constants)

func (Backoff) Retry

func (b Backoff) Retry(f Retryable) error

Retry executes the function and waits for it to end successul or for the given limites to be reached. The returned error uses Go1.13 wrapping of errors and can be unwrapped into the error of the function itself.

func (*Backoff) WithMaxIterationTime added in v2.11.0

func (b *Backoff) WithMaxIterationTime(v time.Duration) *Backoff

WithMaxIterationTime is a wrapper around setting the MaxIterationTime and then returning the Backoff object to use in chained creation

func (*Backoff) WithMaxIterations added in v2.11.0

func (b *Backoff) WithMaxIterations(v uint64) *Backoff

WithMaxIterations is a wrapper around setting the MaxIterations and then returning the Backoff object to use in chained creation

func (*Backoff) WithMaxTotalTime added in v2.11.0

func (b *Backoff) WithMaxTotalTime(v time.Duration) *Backoff

WithMaxTotalTime is a wrapper around setting the MaxTotalTime and then returning the Backoff object to use in chained creation

func (*Backoff) WithMinIterationTime added in v2.11.0

func (b *Backoff) WithMinIterationTime(v time.Duration) *Backoff

WithMinIterationTime is a wrapper around setting the MinIterationTime and then returning the Backoff object to use in chained creation

func (*Backoff) WithMultiplier added in v2.11.0

func (b *Backoff) WithMultiplier(v float64) *Backoff

WithMultiplier is a wrapper around setting the Multiplier and then returning the Backoff object to use in chained creation

type Retryable

type Retryable func() error

Retryable is a function which takes no parameters and yields an error when it should be retried and nil when it was successful

Jump to

Keyboard shortcuts

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