Documentation
¶
Overview ¶
Package retry provides configurable retry strategies and utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDispatcherClosed = errors.New("dispatcher is closed")
ErrDispatcherClosed is returned when attempting to dispatch a task through a closed Dispatcher.
Functions ¶
func Do ¶ added in v0.3.1
Do executes a function with retries according to the provided backoff strategy. Retries the function on failure until it succeeds, the context is cancelled, the backoff strategy indicates stopping or a non-retryable error is returned by the function. Returns the last error if all retries fail, or nil on success.
Types ¶
type Backoff ¶
type Backoff interface {
// Next returns the next wait duration and whether to retry.
Next() (delay time.Duration, ok bool)
// Attempt returns the number of retries attempted so far.
Attempt() int
// Reset restarts the backoff counter to the initial state.
Reset()
}
Backoff implements a retry strategy with increasing delays.
var NoBackoff Backoff = &noRetry{}
NoBackoff is a Backoff that immediately stops retrying. Useful for disabling retries or as a terminal condition.
func Exponential ¶
Exponential creates a backoff with doubling delays.
type DispatchFunc ¶ added in v0.5.0
DispatchFunc is a function Dispatcher uses to dispatch tasks.
type Dispatcher ¶ added in v0.3.0
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher creates and dispatches tasks with retries according to backoff strategies.
func NewDispatcher ¶ added in v0.3.0
func NewDispatcher(fn DispatchFunc) *Dispatcher
NewDispatcher creates a new dispatcher. Dispatcher will dispatch tasks for execution using the provided function.
func (*Dispatcher) Close ¶ added in v0.3.0
func (d *Dispatcher) Close()
Close closes the dispatcher and stops all retries.
type Wrapper ¶ added in v0.2.0
Wrapper is a function that decorates a Backoff with additional behavior.
func Jitter ¶
Jitter randomizes delays from another backoff by ±j. The delay can never be less than 0.
func MaxDuration ¶
MaxDuration limits the cumulative delay time from a backoff. It's best-effort, and should not be used to guarantee an exact amount of time.
func MaxRetries ¶
MaxRetries caps the number of retries for another backoff.