retry

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package retry provides exponential backoff retry logic for transient failures in RPC calls, HTTP requests, and transaction submissions.

Index

Constants

This section is empty.

Variables

View Source
var ErrMaxRetries = errors.New("max retries exceeded")

ErrMaxRetries is returned when all retry attempts are exhausted. The underlying cause is wrapped: errors.Is(err, ErrMaxRetries) == true.

Functions

func Do

func Do[T any](ctx context.Context, fn func(context.Context) (T, error), opts ...Option) (T, error)

Do executes fn with retry logic. It returns the result of the first successful call or ErrMaxRetries wrapping the last error.

Types

type Config

type Config struct {
	MaxRetries   int
	InitialDelay time.Duration
	MaxDelay     time.Duration
	Multiplier   float64
	RetryIf      func(error) bool // nil = retry all non-context errors
}

Config holds retry parameters.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Option

type Option func(*Config)

Option configures retry behavior.

func WithInitialDelay

func WithInitialDelay(d time.Duration) Option

WithInitialDelay sets the base delay before the first retry.

func WithMaxDelay

func WithMaxDelay(d time.Duration) Option

WithMaxDelay sets the upper bound on backoff delay.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries sets the maximum number of retries (not counting the initial attempt).

func WithMultiplier

func WithMultiplier(m float64) Option

WithMultiplier sets the exponential backoff multiplier.

func WithRetryIf

func WithRetryIf(fn func(error) bool) Option

WithRetryIf sets a predicate that determines whether an error is retryable. If the predicate returns false, the error is returned immediately without wrapping.

Jump to

Keyboard shortcuts

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