Documentation ¶
Overview ¶
Package retry provides a generic retry mechanism with exponential backoff.
Example:
ctx := context.Background() client := foobar.NewClient() err := retry.Do(func() error { err := client.UpdateConfig(ctx, map[string]any{"key": "value"}) // will be retied if errors.Is(err, foobar.ErrTxConflict) { return retry.Retryable(err) } return err })
Index ¶
- func Do(cb Callback) error
- func DoTyped[T any](cb TypedCallback[T]) (T, error)
- func DoTypedWithBackoff[T any](cb TypedCallback[T], bo Backoff) (T, error)
- func DoTypedWithBackoffAndRetry[T any](cb TypedCallback[T], bo Backoff) (T, error)
- func DoTypedWithRetry[T any](cb TypedCallback[T]) (T, error)
- func DoWithBackoff(cb Callback, bo Backoff) error
- func Retry(err error) error
- func RetryTyped[T any](result T, err error) (T, error)
- type Backoff
- type Callback
- type TypedCallback
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
Do executes the callback function with the default backoff config. It will retry a callback ONLY if error is retryable.
func DoTyped ¶
func DoTyped[T any](cb TypedCallback[T]) (T, error)
DoTyped is typed version of Do that returns a value along with an error. It will retry a callback ONLY if error is retryable.
func DoTypedWithBackoff ¶
func DoTypedWithBackoff[T any](cb TypedCallback[T], bo Backoff) (T, error)
DoTypedWithBackoff is typed version of DoWithBackoff that returns a value along with an error. It will retry a callback ONLY if error is retryable.
func DoTypedWithBackoffAndRetry ¶
func DoTypedWithBackoffAndRetry[T any](cb TypedCallback[T], bo Backoff) (T, error)
DoTypedWithBackoffAndRetry is DoTypedWithBackoff but ANY error is retried.
func DoTypedWithRetry ¶
func DoTypedWithRetry[T any](cb TypedCallback[T]) (T, error)
DoTypedWithRetry is DoTyped but ANY error is retried.
func DoWithBackoff ¶
DoWithBackoff executes the callback function with provided backoff config. It will retry a callback ONLY if error is retryable.
func RetryTyped ¶
RetryTyped wraps error to mark it as retryable
Types ¶
type Backoff ¶
type Backoff = backoff.BackOff
func DefaultBackoff ¶
func DefaultBackoff() Backoff
DefaultBackoff returns a default backoff strategy with 5 exponential retries.