retry

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package retry provides utilities for retrying operations with exponential backoff.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, cfg Config, fn func() error) error

Do executes the given function with retry logic. The function is retried up to MaxAttempts times with exponential backoff and jitter. Returns nil if the function succeeds, or the last error if all attempts fail.

func DoWithData

func DoWithData[T any](ctx context.Context, cfg Config, fn func() (T, error)) (T, error)

DoWithData executes a function that returns data, with retry logic. Similar to Do but for functions that return values.

Types

type Config

type Config struct {
	// MaxAttempts is the maximum number of retry attempts
	MaxAttempts int
	// InitialDelay is the delay before the first retry
	InitialDelay time.Duration
	// MaxDelay is the maximum delay between retries
	MaxDelay time.Duration
	// Multiplier is the factor by which delay increases after each attempt
	Multiplier float64
	// Jitter is the maximum random variation added to delays (0.0 to 1.0)
	Jitter float64
}

Config configures retry behavior.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default retry configuration.

Jump to

Keyboard shortcuts

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