package backoff
import "github.com/jpillora/backoff"
Package backoff provides an exponential-backoff implementation.
Index ¶
Types ¶
type Backoff ¶
type Backoff struct { // Factor is the multiplying factor for each increment step Factor float64 // Jitter eases contention by randomizing backoff steps Jitter bool // Min and Max are the minimum and maximum values of the counter Min, Max time.Duration // contains filtered or unexported fields }
Backoff is a time.Duration counter, starting at Min. After every call to the Duration method the current timing is multiplied by Factor, but it never exceeds Max.
Backoff is not generally concurrent-safe, but the ForAttempt method can be used concurrently.
func (*Backoff) Attempt ¶
Attempt returns the current attempt counter value.
func (*Backoff) Copy ¶
Copy returns a backoff with equals constraints as the original
func (*Backoff) Duration ¶
Duration returns the duration for the current attempt before incrementing the attempt counter. See ForAttempt.
func (*Backoff) ForAttempt ¶
ForAttempt returns the duration for a specific attempt. This is useful if you have a large number of independent Backoffs, but don't want use unnecessary memory storing the Backoff parameters per Backoff. The first attempt should be 0.
ForAttempt is concurrent-safe.
func (*Backoff) Reset ¶
func (b *Backoff) Reset()
Reset restarts the current attempt counter at zero.
Source Files ¶
- Version
- v1.0.0 (latest)
- Published
- Oct 3, 2019
- Platform
- linux/amd64
- Imports
- 4 packages
- Last checked
- now –
Tools for package owners.