Documentation
¶
Index ¶
- Constants
- func Run(function func() error, attempts int, sleep time.Duration) (err error)
- func RunWithDefaultDownloadBackoff(function func() error, cancel <-chan struct{}) (wasCancelled bool, err error)
- func RunWithExpBackoff(function func() error, attempts int, sleep time.Duration, ...) (wasCancelled bool, err error)
- func RunWithLinearBackoff(function func() error, attempts int, sleep time.Duration, ...) (wasCancelled bool, err error)
Constants ¶
const ( // With 5 attempts (4 retries) and a backoff factor of 2 seconds the total time spent retrying will be approximately: // 1 + 4 + 8 + 16 = 31 seconds. DefaultDownloadBackoffBase = 2.0 DefaultDownloadRetryAttempts = 5 DefaultDownloadRetryDuration = time.Second )
Variables ¶
This section is empty.
Functions ¶
func Run ¶
Run runs function up to 'attempts' times, waiting i * sleep duration before each i-th attempt.
func RunWithDefaultDownloadBackoff ¶
func RunWithDefaultDownloadBackoff(function func() error, cancel <-chan struct{}) (wasCancelled bool, err error)
RunWithDefaultDownloadBackoff runs function up to 'DefaultDownloadRetryAttempts' times, waiting 'DefaultDownloadBackoffBase^(i-1)' seconds before each i-th attempt. An optional cancel channel can be provided to cancel the retry loop immediately by closing the channel.
The function is meant as a default for network download operations.
func RunWithExpBackoff ¶
func RunWithExpBackoff(function func() error, attempts int, sleep time.Duration, backoffExponentBase float64, cancel <-chan struct{}) (wasCancelled bool, err error)
RunWithExpBackoff runs function up to 'attempts' times, waiting 'backoffExponentBase^(i-1) * sleep' duration before each i-th attempt. An optional cancel channel can be provided to cancel the retry loop immediately by closing the channel.
func RunWithLinearBackoff ¶
func RunWithLinearBackoff(function func() error, attempts int, sleep time.Duration, cancel <-chan struct{}) (wasCancelled bool, err error)
RunWithLinearBackoff runs function up to 'attempts' times, waiting i * sleep duration before each i-th attempt. An optional cancel channel can be provided to cancel the retry loop immediately by closing the channel.
Types ¶
This section is empty.