Documentation
¶
Index ¶
- type ErrRecovered
- type Retry
- type RetryInfo
- type RetryOption
- type RetryPolicy
- func Combine(policies ...RetryPolicy) RetryPolicy
- func Constant(interval time.Duration) RetryPolicy
- func Exponential(interval time.Duration) RetryPolicy
- func Jitter(interval time.Duration) RetryPolicy
- func LimitCount(count int) RetryPolicy
- func LimitTime(limit time.Duration) RetryPolicy
- func Linear(interval time.Duration) RetryPolicy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrRecovered ¶ added in v0.2.0
type ErrRecovered struct{ V any }
ErrRecovered is returned when a panic is recovered.
func (ErrRecovered) Error ¶ added in v0.2.0
func (e ErrRecovered) Error() string
type Retry ¶
type Retry[T any] struct { // contains filtered or unexported fields }
Retry is the main type of this package.
func New ¶
func New[T any](policy RetryPolicy, options ...RetryOption[T]) (Retry[T], error)
New creates a new Retry instance with the given RetryPolicy and RetryOptions.
func NewZero ¶ added in v0.3.2
func NewZero(policy RetryPolicy, options ...RetryOption[zero]) (Retry[zero], error)
NewZero creates a new Retry instance with no return value.
type RetryInfo ¶
type RetryInfo struct {
Fails int // Fails is the number of retries
Err error // Err is the error returned by the function
Since time.Time // Since is the time when the retry started
}
RetryInfo contains information about the retry
type RetryOption ¶ added in v0.3.1
type RetryOption[T any] interface { // contains filtered or unexported methods }
type RetryOption[T any] func(*Retry[T])
func WithRecovery ¶ added in v0.2.0
func WithRecovery[T any]() RetryOption[T]
WithRecovery enables the recovery mode.
type RetryPolicy ¶
RetryPolicy is a function that returns a retry strategy based on the RetryInfo
func Combine ¶
func Combine(policies ...RetryPolicy) RetryPolicy
Combine returns a RetryPolicy that combines multiple RetryPolicies. The function will return true if all the policies return true. (logical AND) If all the policies return true, the function will return the sum of the sleep durations.
Sleep formula: sleep1 + sleep2 + ...
func Constant ¶
func Constant(interval time.Duration) RetryPolicy
Constant returns a RetryPolicy that always returns the same interval between retries.
Sleep formula: interval
func Exponential ¶
func Exponential(interval time.Duration) RetryPolicy
Exponential returns a RetryPolicy that increases the interval between retries exponentially.
Sleep formula: interval * 2^fails
func Jitter ¶
func Jitter(interval time.Duration) RetryPolicy
Jitter returns a RetryPolicy that adds a random non-negative jitter to the interval between retries.
Sleep formula: interval + rand.Int63n(interval)
func LimitCount ¶
func LimitCount(count int) RetryPolicy
LimitCount returns a RetryPolicy that limits the number of retries.
Sleep formula: 0
func LimitTime ¶
func LimitTime(limit time.Duration) RetryPolicy
LimitTime returns a RetryPolicy that limits the total time spent on retries.
Sleep formula: 0
WARNING: Use context.WithTimeout instead of this function if you can!
func Linear ¶
func Linear(interval time.Duration) RetryPolicy
Linear returns a RetryPolicy that increases the interval between retries linearly.
Sleep formula: interval * fails
