retry

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// INFINITE_ATTEMPT for unlimited attempt.
	INFINITE_ATTEMPT = -1

	// Errros.
	ERR_INVALID_MAX_ATTEMPT = errors.New("MaxAttempt must be -1 (INFINITE_ATTEMPT) or > 0")
	ERR_MISSING_WORK_FN     = errors.New("WorkFn can't be empty")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxAttempt refer to maximum attempts are allowed (start from 0).
	// Use INFINITE_ATTEMPT for unlimited attempt
	MaxAttempt int

	// Delay will delay each attempt.
	Delay Delay
}

Config provides configuration to run the retry.

func (*Config) Do

func (conf *Config) Do(workFn func() (interface{}, error)) (res interface{}, err error)

Do runs retry with given workFn.

type Delay

type Delay struct {
	Type     DelayType
	Duration time.Duration
}

Delay provides configuration to run the delay.

func (*Delay) Do

func (delay *Delay) Do(attempt int)

Do will execute delay.

type DelayType

type DelayType string

DelayType is delay's type.

const (
	NORMAL  DelayType = "normal"
	BACKOFF DelayType = "backoff"
)

DelayTypes.

type Retry

type Retry interface {
	Do(workFn func() (interface{}, error)) (res interface{}, err error)
	// contains filtered or unexported methods
}

Retry provides list of retry's functions.

func New

func New(conf Config) (Retry, error)

New creates retry base on given config.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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