Categorygithub.com/cenkalti/backoff/v5
modulepackage
5.0.2
Repository: https://github.com/cenkalti/backoff.git
Documentation: pkg.go.dev

# README

Exponential Backoff GoDoc

This is a Go port of the exponential backoff algorithm from Google's HTTP Client Library for Java.

Exponential backoff is an algorithm that uses feedback to multiplicatively decrease the rate of some process, in order to gradually find an acceptable rate. The retries exponentially increase and stop increasing when a certain threshold is met.

Usage

Import path is github.com/cenkalti/backoff/v5. Please note the version part at the end.

For most cases, use Retry function. See example_test.go for an example.

If you have specific needs, copy Retry function (from retry.go) into your code and modify it as needed.

Contributing

  • I would like to keep this library as small as possible.
  • Please don't send a PR without opening an issue and discussing it first.
  • If proposed change is not a common use case, I will probably not accept it.

# Functions

NewExponentialBackOff creates an instance of ExponentialBackOff using default values.
NewTicker returns a new Ticker containing a channel that will send the time at times specified by the BackOff argument.
Permanent wraps the given err in a *PermanentError.
Retry attempts the operation until success, a permanent error, or backoff completion.
RetryAfter returns a RetryAfter error that specifies how long to wait before retrying.
WithBackOff configures a custom backoff strategy.
WithMaxElapsedTime limits the total duration for retry attempts.
WithMaxTries limits the number of retry attempts.
WithNotify sets a notification function to handle retry errors.

# Constants

Default values for ExponentialBackOff.
DefaultMaxElapsedTime sets a default limit for the total retry duration.
Default values for ExponentialBackOff.
Default values for ExponentialBackOff.
Default values for ExponentialBackOff.
Stop indicates that no more retries should be made for use in NextBackOff().

# Structs

ConstantBackOff is a backoff policy that always returns the same backoff delay.
ExponentialBackOff is a backoff implementation that increases the backoff period for each retry attempt using a randomization function that grows exponentially.
PermanentError signals that the operation should not be retried.
RetryAfterError signals that the operation should be retried after the given duration.
StopBackOff is a fixed backoff policy that always returns backoff.Stop for NextBackOff(), meaning that the operation should never be retried.
Ticker holds a channel that delivers `ticks' of a clock at times reported by a BackOff.
ZeroBackOff is a fixed backoff policy whose backoff time is always zero, meaning that the operation is retried immediately without waiting, indefinitely.

# Interfaces

BackOff is a backoff policy for retrying an operation.

# Type aliases

Notify is a function called on operation error with the error and backoff duration.
Operation is a function that attempts an operation and may be retried.