Documentation
¶
Overview ¶
Package retry provides small context-aware retry and backoff primitives.
Index ¶
- func Do(ctx context.Context, policy Policy, shouldRetry ShouldRetry, ...) error
- func DoValue[T any](ctx context.Context, policy Policy, shouldRetry ShouldRetry, ...) (T, error)
- func Wait(ctx context.Context, delay time.Duration) error
- type Attempt
- type DecorrelatedJitterConfig
- type DelayFunc
- type DelayInput
- type ExponentialConfig
- type Policy
- type ShouldRetry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(ctx context.Context, policy Policy, shouldRetry ShouldRetry, fn func(context.Context) error) error
Do retries fn until it succeeds, shouldRetry rejects the error, attempts are exhausted, or ctx is canceled.
Types ¶
type DecorrelatedJitterConfig ¶
type DecorrelatedJitterConfig struct {
}
DecorrelatedJitterConfig bounds a decorrelated-jitter delay sequence.
type DelayFunc ¶
type DelayFunc func(DelayInput) time.Duration
DelayFunc computes the delay before the next attempt.
func DecorrelatedJitter ¶
func DecorrelatedJitter(config DecorrelatedJitterConfig) DelayFunc
DecorrelatedJitter returns a per-operation delay strategy whose next value is sampled between the base delay and three times the previous delay.
func Exponential ¶
func Exponential(config ExponentialConfig) DelayFunc
Exponential returns a delay strategy whose first delay is BaseDelay and whose later delays double without exceeding MaxDelay.
type DelayInput ¶
DelayInput describes the failed attempt for which a retry delay is needed.
type ExponentialConfig ¶
ExponentialConfig bounds a deterministic doubling delay sequence.
type Policy ¶
type Policy struct {
MaxAttempts int
Delay DelayFunc
Sleep func(context.Context, time.Duration) error
OnRetry func(context.Context, Attempt) error
}
Policy configures retry attempts and their delay strategy.
type ShouldRetry ¶
ShouldRetry reports whether an operation error should be retried.