retry

package
v0.0.0-...-8023e94 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 4 Imported by: 4

Documentation

Index

Constants

View Source
const Stop time.Duration = -1

Stop indicates that no more retries should be made.

Variables

This section is empty.

Functions

func Retry

func Retry(ctx context.Context, b Backoff, f func() error, c chan<- error) error

Retry the operation using the provided back-off policy until it succeeds, or the context is cancelled. Any intermediate errors (but not the final error) returned by the function will be sent on the given channel, if the channel is non-nil.

Types

type Backoff

type Backoff interface {
	// Next gets the duration to wait before retrying the operation or |Stop|
	// to indicate that no retries should be made.
	Next() time.Duration

	// Reset resets to initial state.
	Reset()
}

func NoRetries

func NoRetries() Backoff

NoRetries returns a backoff that will do a single attempt, with no retries.

func WithMaxAttempts

func WithMaxAttempts(b Backoff, max uint64) Backoff

WithMaxAttempts wraps a back-off which stops after |max| attempts. If the max is 0, then it won't apply a maximum number attempts.

func WithMaxDuration

func WithMaxDuration(b Backoff, max time.Duration) Backoff

WithMaxDuration wraps a back-off which stops attempting retries after |max| duration.

type ConstantBackoff

type ConstantBackoff struct {
	// contains filtered or unexported fields
}

ConstantBackoff is a fixed policy that always returns the same backoff delay.

func NewConstantBackoff

func NewConstantBackoff(d time.Duration) *ConstantBackoff

func (*ConstantBackoff) Next

func (b *ConstantBackoff) Next() time.Duration

func (*ConstantBackoff) Reset

func (b *ConstantBackoff) Reset()

type ExponentialBackoff

type ExponentialBackoff struct {
	// contains filtered or unexported fields
}

ExponentialBackoff is a policy that increase the delay exponentially, with a small amount of randomness.

func NewExponentialBackoff

func NewExponentialBackoff(initialInterval time.Duration, maxInterval time.Duration, multiplier float64) *ExponentialBackoff

NewExponentialBackoff returns a new ExponentialBackoff object.

func (*ExponentialBackoff) Next

func (e *ExponentialBackoff) Next() time.Duration

func (*ExponentialBackoff) Reset

func (e *ExponentialBackoff) Reset()

type ZeroBackoff

type ZeroBackoff struct{}

ZeroBackoff is a fixed policy whose back-off time is always zero, meaning that the operation is retried immediately without waiting.

func (*ZeroBackoff) Next

func (b *ZeroBackoff) Next() time.Duration

func (*ZeroBackoff) Reset

func (b *ZeroBackoff) Reset()

Jump to

Keyboard shortcuts

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