retry

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectedError

func ExpectedError(err error) error

ExpectedError error represents an error that is expected by the retrying function. This error is ignored.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout reutrns if the provided error is a timeout error.

func UnexpectedError

func UnexpectedError(err error) error

UnexpectedError error represents an error that is unexpected by the retrying function. This error is fatal.

Types

type ConstantTicker

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

ConstantTicker represents a ticker with a constant algorithm.

func NewConstantTicker

func NewConstantTicker(opts *Options) *ConstantTicker

NewConstantTicker is a ticker that sends the time on a channel using a constant algorithm.

func (ConstantTicker) Jitter

func (t ConstantTicker) Jitter() time.Duration

func (ConstantTicker) Stop

func (t ConstantTicker) Stop()

func (ConstantTicker) StopChan

func (t ConstantTicker) StopChan() <-chan struct{}

func (ConstantTicker) Tick

func (c ConstantTicker) Tick() time.Duration

Tick implements the Ticker interface.

type ErrorSet

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

ErrorSet represents a set of unique errors.

func (*ErrorSet) Append

func (e *ErrorSet) Append(err error) error

Append adds the error to the set if the error is not already present.

func (*ErrorSet) Error

func (e *ErrorSet) Error() string

type ExponentialTicker

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

ExponentialTicker represents a ticker with a truncated exponential algorithm. Please see https://en.wikipedia.org/wiki/Exponential_backoff for details on the algorithm.

func NewExponentialTicker

func NewExponentialTicker(opts *Options) *ExponentialTicker

NewExponentialTicker is a ticker that sends the time on a channel using a truncated exponential algorithm.

func (ExponentialTicker) Jitter

func (t ExponentialTicker) Jitter() time.Duration

func (ExponentialTicker) Stop

func (t ExponentialTicker) Stop()

func (ExponentialTicker) StopChan

func (t ExponentialTicker) StopChan() <-chan struct{}

func (*ExponentialTicker) Tick

func (e *ExponentialTicker) Tick() time.Duration

Tick implements the Ticker interface.

type LinearTicker

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

LinearTicker represents a ticker with a linear algorithm.

func NewLinearTicker

func NewLinearTicker(opts *Options) *LinearTicker

NewLinearTicker is a ticker that sends the time on a channel using a linear algorithm.

func (LinearTicker) Jitter

func (t LinearTicker) Jitter() time.Duration

func (LinearTicker) Stop

func (t LinearTicker) Stop()

func (LinearTicker) StopChan

func (t LinearTicker) StopChan() <-chan struct{}

func (*LinearTicker) Tick

func (l *LinearTicker) Tick() time.Duration

Tick implements the Ticker interface.

type Option

type Option func(*Options)

Option is the functional option func.

func WithJitter

func WithJitter(o time.Duration) Option

WithJitter is a functional option for setting the jitter flag.

func WithUnits

func WithUnits(o time.Duration) Option

WithUnits is a functional option for setting the units of the ticker.

type Options

type Options struct {
	Units  time.Duration
	Jitter time.Duration
}

Options is the functional options struct.

func NewDefaultOptions

func NewDefaultOptions(setters ...Option) *Options

NewDefaultOptions initializes a Options struct with default values.

type RetryableFunc

type RetryableFunc func() error

RetryableFunc represents a function that can be retried.

type Retryer

type Retryer interface {
	Retry(RetryableFunc) error
}

Retryer defines the requirements for retrying a function.

func Constant

func Constant(duration time.Duration, setters ...Option) Retryer

Constant initializes and returns a constant Retryer.

func Exponential

func Exponential(duration time.Duration, setters ...Option) Retryer

Exponential initializes and returns a truncated exponential Retryer.

func Linear

func Linear(duration time.Duration, setters ...Option) Retryer

Linear initializes and returns a linear Retryer.

type Ticker

type Ticker interface {
	Tick() time.Duration
	StopChan() <-chan struct{}
	Stop()
}

Ticker defines the requirements for providing a clock to the retry logic.

type TimeoutError

type TimeoutError struct{}

TimeoutError represents a timeout error.

func (TimeoutError) Error

func (TimeoutError) Error() string

Jump to

Keyboard shortcuts

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