util

package
v0.0.0-...-d3fb13d Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(ctx context.Context, f func() (any, error), opts ...func(*RetryConfig)) (any, error)

Retry executes the provided function with retry logic based on the configuration. It stops on success, unrecoverable errors, context cancellation, or exceeding the retry limits.

func WithInitialInterval

func WithInitialInterval(interval time.Duration) func(*RetryConfig)

WithInitialInterval sets the initial interval between retries.

func WithMaxAttempts

func WithMaxAttempts(attempts int) func(*RetryConfig)

WithMaxAttempts sets the maximum number of retry attempts.

func WithMaxElapsedTime

func WithMaxElapsedTime(duration time.Duration) func(*RetryConfig)

WithMaxElapsedTime sets the maximum time allowed for retries.

func WithMaxInterval

func WithMaxInterval(interval time.Duration) func(*RetryConfig)

WithMaxInterval sets the maximum interval between retries.

func WithMultiplier

func WithMultiplier(multiplier float64) func(*RetryConfig)

WithMultiplier sets the backoff multiplier for exponential backoff.

func WrapError

func WrapError(err error) error

Types

type RetryConfig

type RetryConfig struct {
	MaxAttempts     int
	InitialInterval time.Duration
	MaxInterval     time.Duration
	Multiplier      float64
	MaxElapsedTime  time.Duration
}

func DefaultRetryConfig

func DefaultRetryConfig() *RetryConfig

type RetryError

type RetryError struct {
	Err error
}

func (RetryError) Error

func (r RetryError) Error() string

func (RetryError) ShouldRetry

func (r RetryError) ShouldRetry() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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