retry

package
v1.85.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(
	ctx context.Context, strategy Strategy,
	fn func(ctx context.Context) (shouldRetry bool, err error),
) error

Retry retries the given function with the given Strategy, until function returns no error, strategy returns stop=true, function returns error and retry=false, or ctx deadline is exceeded.

Types

type Strategy

type Strategy func(count uint) (sleep time.Duration, stop bool)

Strategy represents a retry strategy. See Retry for more details.

DefaultStrategy returns an exponential backoff strategy with a limit of 10, a min sleep time of 1ms and a max sleep time of 1024ms. At most, this strategy yields a retry mechanism that can last approximately 2 seconds.

func CombinedStrategy

func CombinedStrategy(i Strategy, n ...Strategy) Strategy

CombinedStrategy returns a retry strategy that combines all the given strategies using the following rules:

  • If any returns stop=true, then stop=true is returned.
  • If multiple return a sleep time that is non-zero, then the biggest sleep value is used.

func ExponentialStrategy

func ExponentialStrategy(min, max time.Duration) Strategy

ExponentialStrategy returns a retry strategy that never stops but increments the sleep time from min to max in power of 2 increments. A min of zero or less never sleeps.

func LimitStrategy

func LimitStrategy(limit uint) Strategy

LimitStrategy returns a retry strategy that stops after limit number of retries has been reached.

func SequentialStrategy

func SequentialStrategy(every time.Duration) Strategy

SequentialStrategy returns a retry strategy that never stops and retries always after 'every' duration.

Jump to

Keyboard shortcuts

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