backoff

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backoffer

type Backoffer interface {
	Backoff(fn func() error) error
	BackoffCtx(ctx context.Context, fn func(context.Context) error) error
}

Backoffer is an interface to abstract the Runner type into just a the backoff call.

type NoopBackoff

type NoopBackoff struct{}

NoopBackoff is a backoff that is a noop for the backoff. Only calls the func provided to the backoff calls.

func (NoopBackoff) Backoff

func (n NoopBackoff) Backoff(fn func() error) error

Backoff is a backoff runner.

func (NoopBackoff) BackoffCtx

func (n NoopBackoff) BackoffCtx(ctx context.Context, fn func(context.Context) error) error

BackoffCtx is a backoff runner that may be interrupted via the provided context.

type Runner

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

Runner is a backoff runner that will run a backoff func, safe for concurrent use, and provides DI for a backoff callsites.

func New

func New(opts ...RunnerOptFn) Runner

New returns a runner with the defined options. If no options are given, then the new runner is given the defaults for initial and max backoff as well as max calls. The defaults being:

InitBackoff: 1 second
MaxBackoff:	 1 minute
MaxCalls:	 10
Jitter: 	 false

func (Runner) Backoff

func (r Runner) Backoff(fn func() error) error

Backoff runs the given func in a backoff loop defined by the runner type.

func (Runner) BackoffCtx

func (r Runner) BackoffCtx(ctx context.Context, fn func(context.Context) error) error

BackoffCtx runs the given func in a backoff loop defined by the runner type.

func (Runner) New

func (r Runner) New(opts ...RunnerOptFn) Runner

New allows one to create a new runner, with any options, from an existing runner type.

type RunnerOptFn

type RunnerOptFn func(r Runner) Runner

RunnerOptFn is a functional option to set the

func InitBackoff

func InitBackoff(i time.Duration) RunnerOptFn

InitBackoff sets the runners initial backoff time.

func Jitter

func Jitter() RunnerOptFn

Jitter sets the Backoff method to jitter the backoff duration.

func Logger

func Logger(l *logger.L) RunnerOptFn

Logger sets the Logger on the Runner type.

func MaxBackoff

func MaxBackoff(m time.Duration) RunnerOptFn

MaxBackoff sets the runners max backoff time.

func MaxCalls

func MaxCalls(m int) RunnerOptFn

MaxCalls sets the runners max call count.

Jump to

Keyboard shortcuts

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