retries

package
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFinsihed = errors.New("finished all attempts")
)

Functions

func BackoffDelay

func BackoffDelay(n uint, err error, c *Config) time.Duration

This type of delay doubles the timeout between retries as long as it does not overflow int64 of time.Duration

func ConstantDelay

func ConstantDelay(n uint, err error, c *Config) time.Duration

The type of delay that have a constant timeout between retries. The delay is specified through Delay option

func Do

func Do(task BreakableTask, opts ...Option) error

Types

type BreakableTask

type BreakableTask func() error

type Config

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

type DelayType

type DelayType func(n uint, err error, c *Config) time.Duration

type OnRetryCallback

type OnRetryCallback func(trial uint, incomingTimeout time.Duration, err error)

type Option

type Option func(*Config)

func Attempts

func Attempts(number uint) Option

Set a hard concrete number of retries. Default is 3. To retry until working, set to a number less than 1

func Context

func Context(ctx context.Context) Option

Set a context for the execution. If it has a timeout, then it will cancel the execution when the timeout is up

func Delay

func Delay(delay time.Duration) Option

Set a delay between retries. Default is 100ms

func DelayMethod

func DelayMethod(typ DelayType) Option

Set the type of delay to use. Default is ConstantDelay

func MaxDelay

func MaxDelay(max time.Duration) Option

Set the maximum value for a retry.

func OnRetry

func OnRetry(callback OnRetryCallback) Option

Set a callback to be called on retries.

func RetryIf

func RetryIf(del RetryDelegate) Option

Set a delegate that determines when to retry

type RetryDelegate

type RetryDelegate func(err error) bool

Jump to

Keyboard shortcuts

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