Documentation ¶
Index ¶
- func Retry(ctx context.Context, fn func() error, opts ...RetryOption) error
- func RetryRet1[T any](ctx context.Context, fn func() (T, error), opts ...RetryOption) (ret T, _ error)
- type BackoffFunc
- func MaxBackoff(fn BackoffFunc, max time.Duration) BackoffFunc
- func MinBackoff(fn BackoffFunc, min time.Duration) BackoffFunc
- func NewConstantBackoff(d time.Duration) BackoffFunc
- func NewExponentialBackoff(initial time.Duration, doubleEvery int) BackoffFunc
- func NewLinearBackoff(m, b time.Duration) BackoffFunc
- type RetryOption
- type Waiter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Retry ¶
func Retry(ctx context.Context, fn func() error, opts ...RetryOption) error
Retry calls fn until it returns nil. - To only retry on certain errors use WithPredicate to define a predicate. True means retry. - To set the time between retries use WithPulseTrain and specify a pulse train. - To cancel, use the context, otherwise Retry runs until success.
Types ¶
type BackoffFunc ¶
BackoffFunc is called to determine the duration to wait based on a number retries and elapsed total time since the start of the first attempt.
func MaxBackoff ¶
func MaxBackoff(fn BackoffFunc, max time.Duration) BackoffFunc
MaxBackoff modifies fn to not produce values greater than max
func MinBackoff ¶
func MinBackoff(fn BackoffFunc, min time.Duration) BackoffFunc
MinBackoff modifies fn to not produce values less than min
func NewConstantBackoff ¶
func NewConstantBackoff(d time.Duration) BackoffFunc
NewConstantBackoff returns a backoff function
func NewExponentialBackoff ¶
func NewExponentialBackoff(initial time.Duration, doubleEvery int) BackoffFunc
NewExponentialBackoff waits initial the first retry and doubles
func NewLinearBackoff ¶
func NewLinearBackoff(m, b time.Duration) BackoffFunc
NewLinearBackoff returns a linear backoff functions which will increase by m every retry, and a starting duration of b
`d = m * numRetries + b`
type RetryOption ¶
type RetryOption func(rc *retryConfig)
RetryOption is an option used to configure Retry
func WithBackoff ¶
func WithBackoff(bf BackoffFunc) RetryOption
WithBackoff sets a backoff function for Retry to use
func WithPredicate ¶
func WithPredicate(p func(error) bool) RetryOption
WithPredicate sets p as a predicate for the retry if p returns false then Retry exits with the error. if p returns true then Retry continues normally.
type Waiter ¶
type Waiter interface { // Wait returns a channel which will produce a single value, and then nothing. // Wait can return channels which block for different amounts of time. Wait(numRetries int, startTime time.Time) <-chan time.Time // Close releases any resources the waiter has Close() error }
Waiter waits