Documentation ¶
Overview ¶
Package retry wraps retry logic around a a function call.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackoffType ¶
type BackoffType uint8
const ( // Delay does not increase between retries. BackoffConstant BackoffType = iota // Delay is increased by by itself after each attempt. BackoffLinear // Delay is doubled after each attempt. BackoffExponential )
type ErrorHandler ¶
type ErrorHandler func(error)
type Retrier ¶
type Retrier struct {
// contains filtered or unexported fields
}
Retrier will try to call a function a number of times before giving up.
func NewRetrier ¶
func NewRetrier(backoffType BackoffType, attempts uint, delay time.Duration, maxDelay time.Duration, errorHandler ErrorHandler) Retrier
NewRetrier will create a new Retrier instance.
The first three arguments are the same as NewSimpleRetrier.
maxDelay: The maximum delay to wait after an unsuccesful call. Set it to 0 if you don't want a maximum.
handler: a function that will be called if any errors occur before the Retrier gives up. It is safe to set this to nil.
func NewSimpleRetrier ¶
func NewSimpleRetrier(backoffType BackoffType, attempts uint, delay time.Duration) Retrier
NewSimpleRetrier will create a new Retrier instance with no maximum delay or error handler.
backoffType: The backoff strategy to use.
attempts: The number of times to attempt the function call
delay: The delay to wait after an unsuccesful call.