retry

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(f func() error, opts ...Option) error

func DoWithData

func DoWithData[T any](f func() (T, error), opts ...Option) (T, error)

Types

type DelayFunc

type DelayFunc func(attempt uint, err error) time.Duration

func BackOffDelay

func BackOffDelay(delay time.Duration, maxBackOffN uint) DelayFunc

BackOffDelay is a DelayType which increases delay between consecutive retries Delay set delay between retry, default is 100ms

func FixedDelay

func FixedDelay(v time.Duration) DelayFunc

FixedDelay is a DelayType which keeps delay the same through all iterations

func RandomDelay

func RandomDelay(maxJitter time.Duration) DelayFunc

RandomDelay is a DelayType which picks a random delay up to maxJitter

type Error

type Error []error

Error type represents list of errors in retry

func (Error) As

func (e Error) As(target interface{}) bool

func (Error) Error

func (e Error) Error() string

Error method return string representation of Error It is an implementation of error interface

func (Error) Is

func (e Error) Is(target error) bool

func (Error) Last

func (e Error) Last() error

return the direct last error that came from the retried function default is false (return wrapped errors with everything)

func (Error) Unwrap

func (e Error) Unwrap() error

Unwrap the last error for compatibility with `errors.Unwrap()`. When you need to unwrap all errors, you should use `WrappedErrors()` instead.

err := Do(
	func() error {
		return errors.New("original error")
	},
	Attempts(1),
)

fmt.Println(errors.Unwrap(err)) # "original error" is printed

Added in version 4.2.0.

func (Error) WrappedErrors

func (e Error) WrappedErrors() []error

WrappedErrors returns the list of errors that this Error is wrapping. It is an implementation of the `errwrap.Wrapper` interface in package [errwrap](https://github.com/hashicorp/errwrap) so that `retry.Error` can be used with that library.

type Option

type Option func(*retryConfig)

Option represents an option for retry.

func Attempts

func Attempts(attempts uint) Option

Attempts set count of retry. Setting to 0 will retry until the retried function succeeds. default is 3

func Context

func Context(ctx context.Context) Option

func Delay

func Delay(delay DelayFunc) Option

func OnRetry

func OnRetry(f func(attempt uint, err error)) Option

func RetryIf

func RetryIf(f func(attempt uint, err error) bool) Option

Jump to

Keyboard shortcuts

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