Documentation ¶
Overview ¶
Package try provides retry functionality.
var value string err := try.Do(func(attempt int) (retry bool, err error) { var err error value, err = SomeFunction() return attempt < 5, err // try 5 times }) if err != nil { log.Error(err, "somefunction failed") }
This package was created by Mat Ryer and modified to support multierr, the original package is available at:
https://github.com/matryer/try
With the post introducing it at:
https://medium.com/@matryer/retrying-in-golang-quicktip-f688d00e650a#.3r2nbnjwu
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MaxRetries = 10
MaxRetries is the maximum number of retries before bailing.
Functions ¶
func Do ¶
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 ¶
IsMaxRetries checks whether the error is due to hitting the maximum number of retries or not.