retry

package
v0.0.0-...-cbea63e Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2021 License: Apache-2.0, MIT Imports: 1 Imported by: 0

Documentation

Overview

Package retry wraps retry logic around a a function call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackoffType

type BackoffType uint8
const (
	// Delay does not increase between retries.
	BackoffConstant BackoffType = iota
	// Delay is increased by by itself after each attempt.
	BackoffLinear
	// Delay is doubled after each attempt.
	BackoffExponential
)

type ErrorHandler

type ErrorHandler func(error)

type Retrier

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

Retrier will try to call a function a number of times before giving up.

func NewRetrier

func NewRetrier(backoffType BackoffType, attempts uint, delay time.Duration, maxDelay time.Duration, errorHandler ErrorHandler) Retrier

NewRetrier will create a new Retrier instance.

The first three arguments are the same as NewSimpleRetrier.

maxDelay: The maximum delay to wait after an unsuccesful call. Set it to 0 if you don't want a maximum.

handler: a function that will be called if any errors occur before the Retrier gives up. It is safe to set this to nil.

func NewSimpleRetrier

func NewSimpleRetrier(backoffType BackoffType, attempts uint, delay time.Duration) Retrier

NewSimpleRetrier will create a new Retrier instance with no maximum delay or error handler.

backoffType: The backoff strategy to use.

attempts: The number of times to attempt the function call

delay: The delay to wait after an unsuccesful call.

func (Retrier) Try

func (r Retrier) Try(f func() error) error

Try will attempt to call f using the current Retrier settings. Since f does not take any arguments you may need to use a function literal to capture the arguments

r.Try(func() error { return someFunc(foo) })

Jump to

Keyboard shortcuts

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