util

package
v2.8.8 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MaxRetries = 10

MaxRetries is the maximum number of retries before bailing.

Functions

func Do

func Do(fn Func) error

Do keeps trying the function until the second argument returns false, or no error is returned, attempt is started at 1.

A *multierror.Error combining all attempt errors on failure. If the function does not return true before MaxRetries then the combination of all errors that occurred will be returned which IsMaxRetries() will return true for.

func IsMaxRetries

func IsMaxRetries(err error) bool

IsMaxRetries checks whether the error is due to hitting the maximum number of retries or not.

func Limited

func Limited(limit int, unit time.Duration, maxSleep uint, fn func() error) <-chan error

Limited try to do fn in limit times and will sleep in (logarithmic) duration of unit (millisecond, second,etc) and not more than unit * maxSleep. The return channel stream's fn error in each iteration and can be use for blocking or/and if caller is interested

func WithCancel

func WithCancel(ctx context.Context, unit time.Duration, maxSleep uint, fn func() error) <-chan error

WithCancel try to do fn until context will cancel or fn return nil and will sleep in (logarithmic) duration of unit (millisecond, second,etc) and not more than unit * maxSleep. The return channel stream's fn error in each iteration and can be use for blocking or/and if caller is interested

Types

type Func

type Func func(attempt int) (retry bool, err error)

Func represents functions that can be retried.

Jump to

Keyboard shortcuts

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