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),
)
Documentation
¶
Overview ¶
Package backoff provides wrapper functions for "github.com/cenkalti/backoff/v4".
Example ¶
Output: hello
Index ¶
- Constants
- func Apply(exp *backoff.ExponentialBackOff, options ...Option) backoff.BackOff
- func New(options ...Option) backoff.BackOff
- func NewContext(ctx context.Context, options ...Option) backoff.BackOff
- func Retry(fn func() error, options ...Option) error
- func RetryContext(ctx context.Context, fn func() error, options ...Option) error
- func RetryContextR1(ctx context.Context, fn func() error, options ...Option) error
- func RetryContextR2[R1 any](ctx context.Context, fn func() (R1, error), options ...Option) (r1 R1, err error)
- func RetryContextR3[R1, R2 any](ctx context.Context, fn func() (R1, R2, error), options ...Option) (r1 R1, r2 R2, err error)
- 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)
- 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)
- func RetryR1(fn func() error, options ...Option) error
- func RetryR2[R1 any](fn func() (R1, error), options ...Option) (r1 R1, err error)
- func RetryR3[R1, R2 any](fn func() (R1, R2, error), options ...Option) (r1 R1, r2 R2, err error)
- func RetryR4[R1, R2, R3 any](fn func() (R1, R2, R3, error), options ...Option) (r1 R1, r2 R2, r3 R3, err error)
- 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)
- type Option
- func Clock(clock backoff.Clock) Option
- func InitialInterval(d time.Duration) Option
- func MaxElapsedTime(d time.Duration) Option
- func MaxInterval(d time.Duration) Option
- func MaxRetries(max uint64) Option
- func Multiplier(f float64) Option
- func RandomizationFactor(f float64) Option
- func Stop(d time.Duration) Option
Examples ¶
Constants ¶
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 ¶
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 ¶
Retry the function fn until it does not return error or BackOff stops.
BackOff is created by New with options.
func RetryContext ¶
RetryContext the function fn until it does not return error or BackOff stops.
BackOff is created by NewContext with options and ctx.
func RetryContextR1 ¶
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 RetryR2 ¶
RetryR2 the function fn that returns 2 values until it does not return error or BackOff stops.
func RetryR3 ¶
RetryR3 the function fn that returns 3 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 ¶
InitialInterval uses d as InitialInterval.
see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff
func MaxElapsedTime ¶
MaxElapsedTime uses t as MaxElapsedTime.
see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff
func MaxInterval ¶
MaxInterval uses d as MaxInterval.
see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff
func MaxRetries ¶
MaxRetries applies backoff.WithMaxRetries with max.
func Multiplier ¶
Multiplier uses f as Multiplier.
see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff
func RandomizationFactor ¶
RandomizationFactor uses f as RandomizationFactor.
see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#ExponentialBackOff