backoff

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FF bool

FF is set to Fast Forward time during testing. When true delays are 100 times shorter.

Functions

This section is empty.

Types

type Exponential

type Exponential struct {
	// contains filtered or unexported fields
}

Exponential Sleep

func NewExponential

func NewExponential(max time.Duration) *Exponential

NewExponential returns an exponential Sleep. First it sleeps 0.1 sec then 0.2 etc, sleep time is capped at max.

Examples:

Limit by number of retries:

for exp := backoff.NewExponential(10 * time.Second); exp.Retries() < 10; exp.Sleep() {

Limit by time:

end := time.Now().Add(10 * time.Minute)
for exp := backoff.NewExponential(10 * time.Second); !time.Now().After(end); exp.Sleep() {

func (*Exponential) Retries

func (ex *Exponential) Retries() int

Retries returns the number of retries so far.

func (*Exponential) Sleep

func (ex *Exponential) Sleep()

Sleep exponentially longer on each invocation with a limit of max time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL