Documentation ¶
Overview ¶
Package retry implements exponential retry policy.
Index ¶
- func Always(error) bool
- func Never(error) bool
- func Periodically[T any](ctx context.Context, interval time.Duration, count int, desc string, ...) (T, error)
- func PeriodicallyNoValue(ctx context.Context, interval time.Duration, count int, desc string, ...) error
- func WithExponentialBackoff[T any](ctx context.Context, desc string, attempt func() (T, error), ...) (T, error)
- func WithExponentialBackoffMaxRetries[T any](ctx context.Context, count int, desc string, attempt func() (T, error), ...) (T, error)
- func WithExponentialBackoffNoValue(ctx context.Context, desc string, attempt func() error, ...) error
- type IsRetriableFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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 ¶
IsRetriableFunc is a function that determines whether an error is retriable.