backoff

package
v1.4.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPermanent

func IsPermanent(err error) bool

IsPermanent returns true if the error is a PermanentError.

func Permanent

func Permanent(err error) error

Permanent wraps an error to indicate it should not be retried.

Types

type Backoff

type Backoff struct {
	// InitialInterval is the initial duration to wait before the first retry.
	InitialInterval time.Duration
	// MaxInterval is the upper bound on the backoff duration.
	MaxInterval time.Duration
	// Multiplier is the factor by which the backoff interval increases after each failure.
	Multiplier float64
	// MaxElapsedTime is the maximum total time to spend retrying. If 0, retries indefinitely.
	MaxElapsedTime time.Duration
}

Backoff defines an exponential backoff policy for retrying operations.

func New

func New() *Backoff

New returns a Backoff with default values suitable for network operations.

func (*Backoff) Retry

func (b *Backoff) Retry(ctx context.Context, name string, fn func() error) error

Retry executes the given operation fn. If fn returns an error, it waits according to the exponential backoff policy and retries.

type PermanentError

type PermanentError struct {
	Err error
}

PermanentError is an error that should not be retried.

func (*PermanentError) Error

func (e *PermanentError) Error() string

func (*PermanentError) Unwrap

func (e *PermanentError) Unwrap() error

Jump to

Keyboard shortcuts

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