package backoff

import "github.com/google/trillian/client/backoff"

Package backoff allows retrying an operation with backoff.

Index

Types

type Backoff

type Backoff struct {
	Min    time.Duration
	Max    time.Duration
	Factor float64
	Jitter bool
	// contains filtered or unexported fields
}

Backoff specifies the parameters of the backoff algorithm.

func (*Backoff) Duration

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

Duration returns the time to wait on duration x. Every time Duration is called, the returned value will exponentially increase by Factor until Backoff.Max. If Jitter is enabled, will wait an additional random value between 0 and factor^x * min, capped by Backoff.Max.

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset sets the internal iteration count back to 0.

func (*Backoff) Retry

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

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

Source Files

backoff.go

Version
v1.0.4
Published
Dec 5, 2017
Platform
js/wasm
Imports
4 packages
Last checked
4 hours ago

Tools for package owners.