Documentation
¶
Overview ¶
Package retry provides context based retry functionality for functions.
Index ¶
- Variables
- func Do(ctx context.Context, fn func() error, opts ...Option) error
- func DoFor(d time.Duration, fn func() error, opts ...Option) error
- func DoForWithContext(d time.Duration, fn func(context.Context) error, opts ...Option) error
- func DoWithContext(ctx context.Context, fn func(context.Context) error, opts ...Option) error
- func Get[T any](ctx context.Context, fn func() (T, error), opts ...Option) (T, error)
- func GetWithContext[T any](ctx context.Context, fn func(context.Context) (T, error), opts ...Option) (T, error)
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPanic is returned when a panic is rescued. ErrPanic = errors.New("panic") // ErrAbort is returned when retrying an operation will not result in a // different outcome. ErrAbort = errors.New("operation can not be completed") )
Functions ¶
func DoForWithContext ¶
DoForWithContext retries the function and passes the context to it until it returns nil or the given duration has passed.
func DoWithContext ¶
DoWithContext runs the function and passes the context to it until it returns nil or the context is done or canceled.
Types ¶
type Option ¶
type Option func(*Options)
Option is a functional option function for Options.
func Backoff ¶
Backoff is a functional option that sets the backoff factor. On each attempt the delay is multiplied by this factor. The default is 1.0.
func Delay ¶
Delay is a functional option that sets the delay between retries. The default is 2 seconds.
func If ¶
If is a functional option that sets the function to determine if an error should continue the retry. If the function returns true, the retry will continue.
func MaxRetries ¶
MaxRetries is a functional option that sets the maximum number of retries. The default is to retry indefinitely or until the context is done or canceled.
func RescuePanic ¶
func RescuePanic() Option
RescuePanic is a functional option that controls if panics should be rescued.