retry

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0 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 calls an operation again after failures that may pass (a data plane that is still starting, a busy lock), with exponential backoff, until it succeeds, fails for good, its budget is spent or its context ends.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, p Policy, fn func(context.Context) error) error

Do calls fn until it returns nil or a Permanent error, until it fails once the budget has passed, or until ctx ends while Do waits for the next attempt. It returns nil, fn's last error (a permanent one still marked) or ctx.Err().

func IsPermanent

func IsPermanent(err error) bool

IsPermanent reports whether err, or an error it wraps, was marked by Permanent.

func Permanent

func Permanent(err error) error

Permanent marks err as a failure another attempt would only repeat (nil stays nil).

Types

type Policy

type Policy struct {
	// Budget is how long failures are retried: a failure once Budget has
	// passed since the first attempt is the last one.
	Budget time.Duration
	// Delay is the pause after the first failure; it doubles after every
	// further one, up to MaxDelay.
	Delay, MaxDelay time.Duration
	// Attempt bounds each attempt; 0 leaves that to the operation.
	Attempt time.Duration
}

Policy is a retry schedule.

Jump to

Keyboard shortcuts

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