Documentation ¶
Index ¶
- func Do[T any](ctx context.Context, maxAttempts int, strategy Strategy, op func() (T, error)) (T, error)
- func Do0(ctx context.Context, maxAttempts int, strategy Strategy, op func() error) error
- func Do2[T, U any](ctx context.Context, maxAttempts int, strategy Strategy, ...) (T, U, error)
- type ErrFailedPermanently
- type ExponentialStrategy
- type FixedStrategy
- type Strategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do[T any](ctx context.Context, maxAttempts int, strategy Strategy, op func() (T, error)) (T, error)
Do performs the provided Operation up to maxAttempts times with delays in between each retry according to the provided Strategy.
Types ¶
type ErrFailedPermanently ¶
type ErrFailedPermanently struct { LastErr error // contains filtered or unexported fields }
ErrFailedPermanently is an error raised by Do when the underlying Operation has been retried maxAttempts times.
func (*ErrFailedPermanently) Error ¶
func (e *ErrFailedPermanently) Error() string
func (*ErrFailedPermanently) Unwrap ¶
func (e *ErrFailedPermanently) Unwrap() error
type ExponentialStrategy ¶
type ExponentialStrategy struct { // Min is the minimum amount of time to wait between attempts. Min time.Duration // Max is the maximum amount of time to wait between attempts. Max time.Duration // MaxJitter is the maximum amount of random jitter to insert between attempts. // Jitter is added on top of the maximum, if the maximum is reached. MaxJitter time.Duration }
ExponentialStrategy performs exponential backoff. The exponential backoff function is min(e.Min + (2^attempt * second), e.Max) + randBetween(0, e.MaxJitter)
type FixedStrategy ¶
Click to show internal directories.
Click to hide internal directories.