retry

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package retry implements exponential retry policy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Always added in v0.5.2

func Always(error) bool

Always is a retry function that retries all errors.

func Never added in v0.8.0

func Never(error) bool

Never is a retry function that never retries.

func Periodically added in v0.5.2

func Periodically[T any](ctx context.Context, interval time.Duration, count int, desc string, attempt func() (T, error), isRetriableError IsRetriableFunc) (T, error)

Periodically runs the provided attempt until it succeeds, waiting given fixed amount between attempts.

func PeriodicallyNoValue added in v0.5.2

func PeriodicallyNoValue(ctx context.Context, interval time.Duration, count int, desc string, attempt func() error, isRetriableError IsRetriableFunc) error

PeriodicallyNoValue runs the provided attempt until it succeeds, waiting given fixed amount between attempts.

func WithExponentialBackoff

func WithExponentialBackoff[T any](ctx context.Context, desc string, attempt func() (T, error), isRetriableError IsRetriableFunc) (T, error)

WithExponentialBackoff runs the provided attempt until it succeeds, retrying on all errors that are deemed retriable by the provided function. The delay between retries grows exponentially up to a certain limit.

func WithExponentialBackoffMaxRetries added in v0.10.6

func WithExponentialBackoffMaxRetries[T any](ctx context.Context, count int, desc string, attempt func() (T, error), isRetriableError IsRetriableFunc) (T, error)

WithExponentialBackoffMaxRetries is the same as WithExponentialBackoff, additionally it allows customizing the max number of retries before giving up (count parameter). A negative value for count would run this forever.

func WithExponentialBackoffNoValue

func WithExponentialBackoffNoValue(ctx context.Context, desc string, attempt func() error, isRetriableError IsRetriableFunc) error

WithExponentialBackoffNoValue is a shorthand for WithExponentialBackoff except the attempt function does not return any value.

Types

type IsRetriableFunc

type IsRetriableFunc func(err error) bool

IsRetriableFunc is a function that determines whether an error is retriable.

Jump to

Keyboard shortcuts

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