retry

package
v0.0.0-...-d4b7e32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2023 License: MPL-2.0 Imports: 3 Imported by: 2

Documentation

Index

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.

func RetryRet1

func RetryRet1[T any](ctx context.Context, fn func() (T, error), opts ...RetryOption) (ret T, _ error)

RetryRet1 is a convenience function for returning a value from a retry loop.

Types

type BackoffFunc

type BackoffFunc = func(numRetries int, elapsed time.Duration) time.Duration

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL