Documentation
¶
Overview ¶
Package backoff provides wrapper functions for "github.com/cenkalti/backoff/v4".
Example ¶
package main import ( "context" "fmt" "time" backoff "github.com/takumakei/go-backoff" ) func main() { // mockAPI takes 2 parameters, returns 2 values. mockAPI := func(ctx context.Context, name string) (string, error) { return name, nil } ctx := context.Background() // - P2 means that the target function takes 2 parameters. // - R2 means that the target function returns 2 values. // - types of result and err is inferred by the target function. result, err := backoff.RetryP2R2( // the target function to retry when an error occurs mockAPI, // the 1st argument for the target function ctx, // the 2nd argument for the target function "hello", // parameters for ExponentialBackOff backoff.MaxInterval(7*time.Second), backoff.Stop(7*time.Second), backoff.Context(ctx), backoff.MaxRetries(7), ) if err != nil { fmt.Printf("error: %v", err) } else { fmt.Println(result) } }
Output: hello
Index ¶
- func Apply(exp *backoff.ExponentialBackOff, options ...Option) backoff.BackOff
- func New(options ...Option) backoff.BackOff
- func RetryP0R1(fn func() error, options ...Option) error
- func RetryP0R2[R0 any](fn func() (R0, error), options ...Option) (r0 R0, err error)
- func RetryP0R3[R0, R1 any](fn func() (R0, R1, error), options ...Option) (r0 R0, r1 R1, err error)
- func RetryP1R1[P0 any](fn func(P0) error, p0 P0, options ...Option) error
- func RetryP1R2[P0, R0 any](fn func(P0) (R0, error), p0 P0, options ...Option) (R0, error)
- func RetryP1R3[P0, R0, R1 any](fn func(P0) (R0, R1, error), p0 P0, options ...Option) (R0, R1, error)
- func RetryP2R1[P0, P1 any](fn func(P0, P1) error, p0 P0, p1 P1, options ...Option) error
- func RetryP2R2[P0, P1, R0 any](fn func(P0, P1) (R0, error), p0 P0, p1 P1, options ...Option) (R0, error)
- func RetryP2R3[P0, P1, R0, R1 any](fn func(P0, P1) (R0, R1, error), p0 P0, p1 P1, options ...Option) (R0, R1, error)
- type Option
- func Clock(clock backoff.Clock) Option
- func Context(ctx context.Context) 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 ¶
This section is empty.
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, applies options to it, returns it as backoff.BackOff.
func RetryP0R1 ¶
RetryP0R1 calls fn under backoff.Retry with ExponentialBackOff with options.
- fn has zero parameter. (P0)
- fn returns one value of error. (R1)
func RetryP0R2 ¶
RetryP0R2 calls fn under backoff.Retry with ExponentialBackOff with options.
- fn has zero parameter. (P0)
- fn returns 2 values. (R2)
func RetryP0R3 ¶
RetryP0R3 calls fn under backoff.Retry with ExponentialBackOff with options.
- fn has zero parameter. (P0)
- fn returns 3 values. (R3)
func RetryP1R1 ¶
RetryP1R1 calls fn under backoff.Retry with ExponentialBackOff with options.
- fn has one parameter. (P1)
- fn returns one value. (R1)
func RetryP1R2 ¶
RetryP1R2 calls fn under backoff.Retry with ExponentialBackOff with options.
- fn has one parameter. (P1)
- fn returns 2 values. (R2)
func RetryP1R3 ¶
func RetryP1R3[P0, R0, R1 any](fn func(P0) (R0, R1, error), p0 P0, options ...Option) (R0, R1, error)
RetryP1R3 calls fn under backoff.Retry with ExponentialBackOff with options.
- fn has one parameter. (P1)
- fn returns 3 values. (R3)
func RetryP2R1 ¶
RetryP2R1 calls fn under backoff.Retry with ExponentialBackOff with options.
- fn has 2 parameters. (P2)
- fn returns one value. (R1)
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 Context ¶
Context applies backoff.WithContext with ctx.
see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#WithContext
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.
see: https://pkg.go.dev/github.com/cenkalti/backoff/v4#WithMaxRetries
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