backoff

package
v0.0.0-...-1b34cb9 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package backoff is a wrapper of `github.com/cenkalti/backoff/v4`. It is to prevent misuse of `github.com/cenkalti/backoff/v4`, thus application could fall into dead loop.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackOff

type BackOff interface {
	// NextBackOff returns the duration to wait before retrying the next operation.
	NextBackOff() time.Duration
	// Reset to initial state.
	Reset()
	// RetryWithContext tries the operation until it does not return error,
	// or when the context expires, whichever happens first.
	RetryWithContext(ctx context.Context, operation func() error) error
}

BackOff is a backoff policy for retrying an operation.

func NewExponentialBackOff

func NewExponentialBackOff(o Option) BackOff

NewExponentialBackOff creates an istio wrapped ExponentialBackOff. By default, it never stops.

type ExponentialBackOff

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

ExponentialBackOff is a wrapper of backoff.ExponentialBackOff to override its NextBackOff().

func (ExponentialBackOff) NextBackOff

func (b ExponentialBackOff) NextBackOff() time.Duration

func (ExponentialBackOff) Reset

func (b ExponentialBackOff) Reset()

func (ExponentialBackOff) RetryWithContext

func (b ExponentialBackOff) RetryWithContext(ctx context.Context, operation func() error) error

RetryWithContext tries the operation until it does not return error, or when the context expires, whichever happens first. o is guaranteed to be run at least once. RetryWithContext sleeps the goroutine for the duration returned by BackOff after a failed operation returns.

type Option

type Option struct {
	InitialInterval time.Duration
	MaxInterval     time.Duration
}

func DefaultOption

func DefaultOption() Option

Jump to

Keyboard shortcuts

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