Documentation ¶
Overview ¶
Package backoff provides a backoff policies for use in rate limiting.
Example ¶
package main import ( "net/http" "github.com/tradyfinance/backoff" ) func main() { p := backoff.Default() for { _, err := http.Get("http://example.com") if err != nil { break } p.Sleep() } p.Decrease() }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Nil = &Constant{}
Nil is a constant backoff policy with zero delay.
Functions ¶
This section is empty.
Types ¶
type Constant ¶
type Constant struct {
// contains filtered or unexported fields
}
Constant is a backoff policy with a constant delay.
func NewConstant ¶
NewConstant returns a new Constant backoff policy.
func (*Constant) Decrease ¶
func (con *Constant) Decrease()
Decrease implements the Policy interface.
type Exponential ¶
type Exponential struct { Min time.Duration Factor float64 Max time.Duration // contains filtered or unexported fields }
Exponential is a backoff policy with an exponentially changing delay.
func NewExponential ¶
NewExponential returns a new Exponential backoff policy.
func (*Exponential) Decrease ¶
func (exp *Exponential) Decrease()
Decrease implements the Policy interface.
func (*Exponential) Increase ¶
func (exp *Exponential) Increase() time.Duration
Increase implements the Policy interface.
type Jitter ¶
Jitter is a backoff policy that applies jitter to the delay of another backoff policy.
func NewJitter ¶
NewJitter returns a new Jitter backoff policy given a source backoff policy and a jitter factor.
type Linear ¶
type Linear struct { Min time.Duration Step time.Duration Max time.Duration // contains filtered or unexported fields }
Linear is a backoff policy with a linearly changing delay.