retry

package
v0.9.40 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2019 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultSleep         = 1 * time.Second
	ReadableDefaultSleep = "1s"
)

Functions

func Do

func Do(fn Func, retries int, sleep time.Duration) error

Do runs the passed function until the number of retries is reached. Whenever Func returns err it will sleep and Func will be executed again in a recursive fashion. The sleep value is slightly modified on every retry (exponential backoff) to prevent the thundering herd problem (https://en.wikipedia.org/wiki/Thundering_herd_problem). If no value is given to sleep it will defaults to 500ms.

func DoCondition

func DoCondition(fn ConditionFunc, retries int, sleep time.Duration) error

Types

type Condition

type Condition bool
const (
	Break    Condition = true
	Continue Condition = false
)

type ConditionFunc

type ConditionFunc func() (Condition, error)

ConditionFunc returns additional flag determine whether to break retry or not.

type Func

type Func func() error

Func is the function to be executed and eventually retried.

type HTTPFunc

type HTTPFunc func() (*http.Response, error)

HTTPFunc is the function to be executed and eventually retried. The only difference from Func is that it expects an *http.Response on the first returning argument.

Jump to

Keyboard shortcuts

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