Documentation
¶
Index ¶
- func Do(fn func(attempt int) (shouldRetry bool, err error), opts ...Option) error
- func DoTemporaryError(fn func(attempt int) error, opts ...Option) error
- func IsTemporaryError(err error) bool
- func TemporaryError(err error) error
- func Wrap[T, A any](fn func(context.Context, A) (T, error), attempts int, backoff time.Duration) func(context.Context, A) (T, error)
- func Wrap2[T, A, B any](fn func(context.Context, A, B) (T, error), attempts int, backoff time.Duration) func(context.Context, A, B) (T, error)
- type DoTempFunc
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do will retry the given DoFunc until it or an option returns false. The last returned error value (can be nil) of fn will be returned.
fn will be passed the current attempt number (starting with 0).
func DoTemporaryError ¶
DoTemporaryError will retry as long as the error returned from fn is temporary as defined by IsTemporaryError.
func IsTemporaryError ¶
IsTemporaryError will determine if an error is temporary, and thus the action can/should be retried.
func TemporaryError ¶ added in v0.28.0
TemporaryError returns an error that will always be classified as temporary.
Types ¶
type DoTempFunc ¶
DoTempFunc is a simplified version of DoFunc that just returns an error value.
type Option ¶
An Option takes the attempt number and the last error value (can be nil) and should indicate if a retry should be made.
func FibBackoff ¶
FibBackoff will Sleep for f(n) * Duration (+/- 50ms) before each attempt, where f(n) is the value from the Fibonacci sequence for the nth attempt. There is no delay for the first attempt (n=0).