retry

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(retryableFunc RetryableFunc, options ...Option) error

Do runs the function passed in parameter (retryableFunc) until the retry condition is fulfilled or until the context is Done. The following options are supported: - Retry condition: condition for retries to terminate (e.g. retryableFunc has not returned any error, max attempts...) - Retry trigger: trigger to continue in the next try (e.g. Delay, an system event...) - Context: context that can be used to terminate the function By default, these options are applied: - Retry condition: retryableFunc has not returned any error - Retry trigger: 10 milliseconds delay - Context: empty context

Types

type Config

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

type Option

type Option func(*Config)

func WithContext

func WithContext(ctx context.Context) Option

func WithDelay

func WithDelay(delayTime time.Duration) Option

WithDelay sets a retry trigger with a 10 milliseconds delay WithDelay sets the retry trigger function.

func WithErrorIngnored

func WithErrorIngnored() Option

WithErrorIngnored will not stop the loop if no error is returned by the retryable function. WithErrorIngnored sets the retry condition function.

func WithMaxAttempts

func WithMaxAttempts(attempts uint) Option

WithMaxAttempts specifies the maximum number of attempts/retries If no error is returned by the retryable function, then the retries will finished before the number of max attempts is reached. WithMaxAttempts sets the retry condition function.

func WithRetryCondition

func WithRetryCondition(retryCondition RetryCondition) Option

WithRetryCondition sets the retry condition function.

func WithRetryTrigger

func WithRetryTrigger(retryTrigger RetryTrigger) Option

WithRetryTrigger sets the retry trigger function.

type RetryCondition

type RetryCondition func(error) bool

RetryCondition is the function definition specifying if the Do function should continue in an new attempt or not.

type RetryTrigger

type RetryTrigger func(context.Context) <-chan struct{}

RetryTrigger is the function definition specifying when the Do function should continue in an new attempt.

type RetryableFunc

type RetryableFunc func() error

Function definition to be executed and retried.

Jump to

Keyboard shortcuts

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