retry

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Unlicense Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, policy RetryPolicy, fn func(context.Context) error) error

Do executes a function with retries according to the policy.

Types

type ExponentialBackoff

type ExponentialBackoff struct {
	BaseDelay      time.Duration
	MaxDelay       time.Duration
	Retries        int
	AttemptTimeout time.Duration
	// Jitter factor (0.0 to 1.0)
	Jitter float64
}

ExponentialBackoff implements a standard exponential backoff with jitter.

func (*ExponentialBackoff) Backoff

func (b *ExponentialBackoff) Backoff(attempt int) time.Duration

func (*ExponentialBackoff) IsRetryable

func (b *ExponentialBackoff) IsRetryable(err error) bool

func (*ExponentialBackoff) MaxRetries

func (b *ExponentialBackoff) MaxRetries() int

func (*ExponentialBackoff) Timeout

func (b *ExponentialBackoff) Timeout() time.Duration

type RetryPolicy

type RetryPolicy interface {
	// Backoff returns the duration to wait before the next attempt.
	// attempt is 0-indexed.
	Backoff(attempt int) time.Duration
	// MaxRetries returns the maximum number of retry attempts.
	MaxRetries() int
	// Timeout returns the timeout for a single attempt.
	Timeout() time.Duration
	// IsRetryable returns true if the error should be retried.
	IsRetryable(err error) bool
}

RetryPolicy defines the interface for backoff strategies.

Jump to

Keyboard shortcuts

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