retry

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRetry = errors.New("retry")
	ErrExit  = errors.New("exit")
)

Functions

This section is empty.

Types

type Option

type Option func(*Retry)

func WithContext

func WithContext(ctx context.Context) Option

WithContext sets the ctx for Infinite policy retry

func WithDelay

func WithDelay(delay time.Duration) Option

WithDelay sets the delay between retries

func WithLogger

func WithLogger(logger logger) Option

WithLogger sets the logger for the Retry instance

func WithMaxAttempts

func WithMaxAttempts(maxAttempts int) Option

WithMaxAttempts sets the maximum number of attempts

func WithOnFailedFn

func WithOnFailedFn(fn func()) Option

WithOnFailedFn sets the function to be called on failure

func WithOnSuccessFn

func WithOnSuccessFn(fn func()) Option

WithOnSuccessFn sets the function to be called on success

func WithPolicy

func WithPolicy(policy Policy) Option

WithPolicy sets the retry policy

type Policy

type Policy int
const (
	PolicyLinear Policy = iota
	PolicyBackoff
	PolicyInfinite
)

func (Policy) Validate

func (r Policy) Validate() error

Validate validates the retry policy

type Retry

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

Retry represents a retry mechanism

func New

func New(opts ...Option) *Retry

New creates a new Retry instance

maxAttempts: the maximum number of attempts. Default is 5

policy: the retry policy. Default is PolicyBackoff

func (*Retry) Do

func (r *Retry) Do(fn func() error) error

Do - performs the retry mechanism

func (*Retry) SetContext

func (r *Retry) SetContext(ctx context.Context) *Retry

SetContext sets the ctx for Infinite policy retry

func (*Retry) SetDelay

func (r *Retry) SetDelay(delay time.Duration) *Retry

SetDelay sets the delay between retries

func (*Retry) SetLogger

func (r *Retry) SetLogger(logger logger) *Retry

SetLogger sets the logger for the Retry instance

func (*Retry) SetMaxAttempts

func (r *Retry) SetMaxAttempts(maxAttempts int) *Retry

SetMaxAttempts sets the maximum number of attempts

func (*Retry) SetOnFailedFn

func (r *Retry) SetOnFailedFn(fn func()) *Retry

SetOnFailedFn sets the function to be called on failure

func (*Retry) SetOnSuccessFn

func (r *Retry) SetOnSuccessFn(fn func()) *Retry

SetOnSuccessFn sets the function to be called on success

func (*Retry) SetPolicy

func (r *Retry) SetPolicy(policy Policy) *Retry

SetPolicy sets the retry policy

Jump to

Keyboard shortcuts

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