retry

package
v1.20.5 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 5 Imported by: ? modules, 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

Overview

Package retry provides context-aware retry-with-backoff utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithBackoff

func WithBackoff(ctx context.Context, cfg Config, logger *log.Logger, caller string, fn func() error) error

WithBackoff retries fn with exponential backoff, honouring ctx cancellation during sleep intervals. The caller label is used in log messages. Returns the last error from fn if all attempts fail, or nil on success. If ctx is cancelled during a backoff sleep, ctx.Err() is returned immediately.

Types

type Config

type Config struct {
	// MaxRetries is the maximum number of retry attempts (not counting the
	// initial call).  The total number of calls to fn is MaxRetries+1.
	MaxRetries int
	// InitialBackoff is the delay before the first retry; it doubles on each
	// consecutive failure up to MaxBackoff.
	InitialBackoff time.Duration
	// MaxBackoff caps the exponential backoff delay.
	MaxBackoff time.Duration
}

Config controls the parameters for WithBackoff.

Jump to

Keyboard shortcuts

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