retry

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

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

Types

type Config

type Config struct {
	MaxAttempts  int
	InitialDelay time.Duration
	MaxDelay     time.Duration
	Multiplier   float64
	RetryUnknown bool
}

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the recommended retry configuration: 4 attempts with exponential backoff (2s → 4s → 8s, capped at 30s, then scaled by a random factor in [0.5, 1.0) to decorrelate concurrent retries). RetryUnknown is false, so only errors implementing Retryable are retried — plain errors fail fast on the first attempt.

Returns a fresh value each call so caller mutations don't bleed into anyone else's config.

type Retryable

type Retryable interface {
	Retryable() bool
}

Jump to

Keyboard shortcuts

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