retry

package
v2.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(
	ctx context.Context,
	doer Doer,
	wantRetry WantRetry,
	maxAttempts int,
	retryTime time.Duration,
) (res interface{}, err error)

Do executes the doer function, and retries if needed up to maxAttempts

ctx - the context that if cancelled with prevent any more retry attempts
doer - the function that is executed and retried if needed
wantRetry - the function that determines if the doer is retried based on the returned error
maxAttempts - the maximum number of times the doer function will be attempted
retryTime - the initial sleep time between requests. The retryTime will exponentially increase on subsequent retries

Types

type Doer

type Doer = func() (interface{}, error)

Doer provides the function signature for the function that is retried if needed

type ErrAttemptsExceededLimit

type ErrAttemptsExceededLimit struct {
	WrappedErr error
}

ErrAttemptsExceededLimit is returned when the number of attempts has reached the maximum permitted

func (ErrAttemptsExceededLimit) Error

func (e ErrAttemptsExceededLimit) Error() string

Error provides the formatted error string for the ErrAttemptsExceededLimit type

type WantRetry

type WantRetry = func(err error) bool

WantRetry provides the function signature for a custom function to determine if the doer function is retried, based on the returned error

Jump to

Keyboard shortcuts

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