Documentation
¶
Overview ¶
Package backoff provides a thread-safe, configurable exponential backoff implementation using atomic operations.
Index ¶
- type Backoff
- func (b *Backoff) Attempts() uint64
- func (b *Backoff) Duration() int64
- func (b *Backoff) GetFactor() float64
- func (b *Backoff) GetJitter() float64
- func (b *Backoff) GetMax() float64
- func (b *Backoff) GetMin() float64
- func (b *Backoff) Reset()
- func (b *Backoff) SetFactor(val float64)
- func (b *Backoff) SetJitter(val float64)
- func (b *Backoff) SetMax(val float64)
- func (b *Backoff) SetMin(val float64)
- type BackoffOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff struct {
// contains filtered or unexported fields
}
Backoff manages exponential backoff state and parameters safely across multiple goroutines. To instantiate a new instance, use the NewBackoff function.
func NewBackoff ¶
func NewBackoff(opts ...BackoffOption) *Backoff
NewBackoff initializes and returns a new *Backoff instance with default values and applies any provided BackoffOption. If the configured minimum value exceeds the maximum value, the minimum will be clamped to the maximum value.
func (*Backoff) Duration ¶
Duration calculates and returns the next backoff duration in nanoseconds. It increments the attempt counter atomically and applies exponential growth and jitter if configured.
func (*Backoff) Reset ¶
func (b *Backoff) Reset()
Reset resets the internal attempt counter back to 0.
func (*Backoff) SetFactor ¶
SetFactor updates the multiplication factor dynamically. The value must be greater than 1 and a valid finite number.
func (*Backoff) SetJitter ¶
SetJitter updates the jitter ratio dynamically. The value must be between 0 and 1 inclusive.
type BackoffOption ¶
type BackoffOption func(*Backoff)
BackoffOption defines a configuration function used to customize a *Backoff instance.
func WithFactor ¶
func WithFactor(factor float64) BackoffOption
WithFactor returns a BackoffOption that configures the multiplication factor. The value must be greater than 1 and a valid finite number.
func WithJitter ¶
func WithJitter(jitter float64) BackoffOption
WithJitter returns a BackoffOption that configures the jitter ratio. The value must be between 0 and 1 inclusive.
func WithMax ¶
func WithMax(max float64) BackoffOption
WithMax returns a BackoffOption that configures the maximum duration. The value must be greater than 0 and a valid finite number.
func WithMin ¶
func WithMin(min float64) BackoffOption
WithMin returns a BackoffOption that configures the minimum duration. The value must be greater than 0 and a valid finite number.