backoff

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

go-backoff

Package backoff provides wrapper functions for "github.com/cenkalti/backoff/v4".

examples

	mockAPI := func(ctx context.Context, name string) (string, error) { return name, nil }

	result, err := backoff.RetryContextR2(
		ctx,
		bind.P2R2(mockAPI, ctx, "hello"),
		backoff.MaxInterval(7*time.Second),
		backoff.Stop(7*time.Second),
		backoff.MaxRetries(7),
	)

see https://pkg.go.dev/github.com/takumakei/go-bind .

Documentation

Overview

Package backoff provides wrapper functions for "github.com/cenkalti/backoff/v4".

Example
Output:

hello

Index

Examples

Constants

View Source
const (
	DefaultInitialInterval     = backoff.DefaultInitialInterval
	DefaultRandomizationFactor = backoff.DefaultRandomizationFactor
	DefaultMultiplier          = backoff.DefaultMultiplier
	DefaultMaxInterval         = backoff.DefaultMaxInterval
	DefaultMaxElapsedTime      = backoff.DefaultMaxElapsedTime
	DefaultStop                = backoff.Stop
)

Default values for ExponentialBackOff.

Variables

This section is empty.

Functions

func Apply

func Apply(exp *backoff.ExponentialBackOff, options ...Option) backoff.BackOff

Apply applies options to exp, returns it as backoff.BackOff.

func New

func New(options ...Option) backoff.BackOff

New creates an backoff.ExponentialBackOff by calling backoff.NewExponentialBackOff, applies options to it, returns it as backoff.BackOff.

func NewContext

func NewContext(ctx context.Context, options ...Option) backoff.BackOff

NewContext creates an backoff.ExponentialBackOff by calling backoff.NewExponentialBackOff, applies options to it, wraps by backoff.WithContext with ctx, returns it as backoff.BackOff.

func Retry

func Retry(fn func() error, options ...Option) error

Retry the function fn until it does not return error or BackOff stops.

BackOff is created by New with options.

func RetryContext

func RetryContext(ctx context.Context, fn func() error, options ...Option) error

RetryContext the function fn until it does not return error or BackOff stops.

BackOff is created by NewContext with options and ctx.

func RetryContextR1

func RetryContextR1(ctx context.Context, fn func() error, options ...Option) error

RetryContextR1 is an alias of RetryContext.

func RetryContextR2

func RetryContextR2[R1 any](ctx context.Context, fn func() (R1, error), options ...Option) (r1 R1, err error)

RetryContextR2 the function fn that returns 2 values until it does not return error or BackOff stops.

func RetryContextR3

func RetryContextR3[R1, R2 any](ctx context.Context, fn func() (R1, R2, error), options ...Option) (r1 R1, r2 R2, err error)

RetryContextR3 the function fn that returns 3 values until it does not return error or BackOff stops.

func RetryContextR4

func RetryContextR4[R1, R2, R3 any](ctx context.Context, fn func() (R1, R2, R3, error), options ...Option) (r1 R1, r2 R2, r3 R3, err error)

RetryContextR4 the function fn that returns 4 values until it does not return error or BackOff stops.

func RetryContextR5

func RetryContextR5[R1, R2, R3, R4 any](ctx context.Context, fn func() (R1, R2, R3, R4, error), options ...Option) (r1 R1, r2 R2, r3 R3, r4 R4, err error)

RetryContextR5 the function fn that returns 5 values until it does not return error or BackOff stops.

func RetryR1

func RetryR1(fn func() error, options ...Option) error

RetryR1 is an alias of Retry.

func RetryR2

func RetryR2[R1 any](fn func() (R1, error), options ...Option) (r1 R1, err error)

RetryR2 the function fn that returns 2 values until it does not return error or BackOff stops.

func RetryR3

func RetryR3[R1, R2 any](fn func() (R1, R2, error), options ...Option) (r1 R1, r2 R2, err error)

RetryR3 the function fn that returns 3 values until it does not return error or BackOff stops.

func RetryR4

func RetryR4[R1, R2, R3 any](fn func() (R1, R2, R3, error), options ...Option) (r1 R1, r2 R2, r3 R3, err error)

RetryR4 the function fn that returns 4 values until it does not return error or BackOff stops.

func RetryR5

func RetryR5[R1, R2, R3, R4 any](fn func() (R1, R2, R3, R4, error), options ...Option) (r1 R1, r2 R2, r3 R3, r4 R4, err error)

RetryR5 the function fn that returns 5 values until it does not return error or BackOff stops.

Types

type Option

type Option func(*builder)

Option is type of setting parameters of ExponentialBackOff.

func Clock

func Clock(clock backoff.Clock) Option

Clock uses clock as Clock.

see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff

func InitialInterval

func InitialInterval(d time.Duration) Option

InitialInterval uses d as InitialInterval.

see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff

func MaxElapsedTime

func MaxElapsedTime(d time.Duration) Option

MaxElapsedTime uses t as MaxElapsedTime.

see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff

func MaxInterval

func MaxInterval(d time.Duration) Option

MaxInterval uses d as MaxInterval.

see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff

func MaxRetries

func MaxRetries(max uint64) Option

MaxRetries applies backoff.WithMaxRetries with max.

func Multiplier

func Multiplier(f float64) Option

Multiplier uses f as Multiplier.

see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff

func RandomizationFactor

func RandomizationFactor(f float64) Option

RandomizationFactor uses f as RandomizationFactor.

see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff

Jump to

Keyboard shortcuts

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