Version: v0.3.0 Latest Latest

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

Go to latest
Published: Jul 3, 2020 License: Apache-2.0 Imports: 7 Imported by: 0



Package backoff allows retrying an operation with backoff.



This section is empty.


This section is empty.


func IsRetryable

func IsRetryable(err error, retry bool

IsRetryable returns false unless the error is explicitly retriable per, or if the error codes is in retry. codes.OK is not retryable.

func RetriableErrorf

func RetriableErrorf(format string, a ...interface{}) error

RetriableErrorf wraps a formatted error into a RetriableError.


type Backoff

type Backoff struct {
	Min    time.Duration // Duration of the first pause.
	Max    time.Duration // Max duration of a pause.
	Factor float64       // The factor of duration increase between iterations.
	Jitter bool          // Add random noise to pauses.
	// contains filtered or unexported fields

Backoff specifies the parameters of the backoff algorithm. Works correctly if 0 < Min <= Max <= 2^62 (nanosec), and Factor >= 1.

func (*Backoff) Duration

func (b *Backoff) Duration() time.Duration

Duration returns the time to wait on current retry iteration. Every time Duration is called, the returned value will exponentially increase by Factor until Backoff.Max. If Jitter is enabled, will add an additional random value between 0 and the duration, so the result can at most double.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset sets the internal state back to first retry iteration.

func (*Backoff) Retry

func (b *Backoff) Retry(ctx context.Context, f func() error, retry error

Retry calls a function until it succeeds or the context is done. It will backoff if the function returns a retryable error. Once the context is done, retries will end and the most recent error will be returned. Backoff is not reset by this function.

type RetriableError

type RetriableError struct {
	// contains filtered or unexported fields

RetriableError explicitly instructs Backoff to retry.

Source Files

Jump to

Keyboard shortcuts

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