Documentation
¶
Index ¶
- Variables
- func DefaultConfig() schema.RetryConfig
- func Do(ctx context.Context, config *schema.RetryConfig, fn Func) error
- func Validate(config *schema.RetryConfig) error
- func With7Params[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](ctx context.Context, config *schema.RetryConfig, ...) error
- func WithPredicate(ctx context.Context, config *schema.RetryConfig, fn Func, ...) error
- type Executor
- type Func
- type MaxElapsedTimeError
Constants ¶
This section is empty.
Variables ¶
var ( ErrMaxAttemptsMustBePositive = errors.New("max_attempts must be greater than zero") ErrMaxElapsedTimeMustBePositive = errors.New("max_elapsed_time must be greater than zero") ErrMultiplierMustBePositive = errors.New("multiplier must be greater than zero") ErrMaxDelayMustBePositive = errors.New("max_delay must be greater than zero") ErrInitialDelayCannotBeNegative = errors.New("initial_delay cannot be negative") ErrRandomJitterOutOfRange = errors.New("random_jitter must be between 0.0 and 1.0") )
Validation errors.
var UnexpectedError = errors.New("unexpected end of retry loop")
UnexpectedError is returned when the retry loop ends unexpectedly.
Functions ¶
func DefaultConfig ¶
func DefaultConfig() schema.RetryConfig
DefaultConfig returns a sensible default configuration for a single attempt. Most fields are nil (disabled/unlimited).
func Do ¶
Do is a convenience function that creates an executor and runs the function. If config is nil, a default single-attempt config is used to ensure consistent error messages (e.g., "max attempts (1) exceeded, last error: ...").
func Validate ¶
func Validate(config *schema.RetryConfig) error
Validate checks that explicitly set values are valid. Returns an error if any field is explicitly set to an invalid value (e.g., zero or negative). Nil values are valid and mean "disabled" or "unlimited".
func With7Params ¶
func With7Params[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](ctx context.Context, config *schema.RetryConfig, fn func(T1, T2, T3, T4, T5, T6, T7) error, a T1, b T2, c T3, d T4, e T5, f T6, g T7, ) error
With7Params is a convenience function for retrying functions with 7 parameters.
func WithPredicate ¶
func WithPredicate(ctx context.Context, config *schema.RetryConfig, fn Func, shouldRetry func(error) bool) error
WithPredicate allows you to specify which errors should trigger a retry. If config is nil, the function is executed once without retry.
Types ¶
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor handles the retry logic.
func New ¶
func New(config schema.RetryConfig) *Executor
New creates a new retry executor with the given config.
type MaxElapsedTimeError ¶
MaxElapsedTimeError is returned when the retry timeout is exceeded.
func (MaxElapsedTimeError) Error ¶
func (e MaxElapsedTimeError) Error() string