wrappers

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 4 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// DefaultDoBackoffTime is the default value of backoff time used by
	// DoWithDefaultRetry function.
	DefaultDoBackoffTime = 1 * time.Second

	// DefaultDoMaxBackoffTime is the default value of max backoff time used by
	// DoWithDefaultRetry function.
	DefaultDoMaxBackoffTime = 120 * time.Second
)
View Source
const (
	// DefaultConfirmBackoffTime is the default value of backoff time used by
	// ConfirmWithDefaultTimeout function.
	DefaultConfirmBackoffTime = 5 * time.Second

	// DefaultConfirmMaxBackoffTime is the default value of max backoff time
	// used by ConfirmWithDefaultTimeout function.
	DefaultConfirmMaxBackoffTime = 10 * time.Second
)

Variables

This section is empty.

Functions

func ConfirmWithTimeout

func ConfirmWithTimeout(
	backoffTime time.Duration,
	backoffMax time.Duration,
	timeout time.Duration,
	confirmFn func(ctx context.Context) (bool, error),
) (bool, error)

ConfirmWithTimeout executes the provided confirmFn until it returns true or until it fails or until a timeout is hit. It applies exponential backoff wait of backoffTime * 2^n before nth execution of confirmFn. In case the calculated backoff is longer than backoffMax, the backoffMax is applied. In case confirmFn returns an error, ConfirmWithTimeout exits with the same error immediately. This is different from DoWithRetry behavior as the use case for this function is different. ConfirmWithTimeout is intended to be used to confirm a chain state and not to try to enforce a successful execution of some function.

func ConfirmWithTimeoutDefaultBackoff

func ConfirmWithTimeoutDefaultBackoff(
	timeout time.Duration,
	confirmFn func(ctx context.Context) (bool, error),
) (bool, error)

ConfirmWithTimeoutDefaultBackoff executed the provided confirmFn until it returns true or until it fails or until timeout is hit. It applies backoff wait of DefaultConfirmBackoffTime * 2^n before nth execution of confirmFn. In case the calculated backoff is longer than DefaultConfirmMaxBackoffTime, DefaultConfirmMaxBackoffTime is applied. In case confirmFn returns an error, ConfirmWithTimeoutDefaultBackoff exits with the same error immediately. This is different from DoWithDefaultRetry behavior as the use case for this function is different. ConfirmWithTimeoutDefaultBackoff is intended to be used to confirm a chain state and not to try to enforce a successful execution of some function.

func DoWithDefaultRetry

func DoWithDefaultRetry(
	timeout time.Duration,
	doFn func(ctx context.Context) error,
) error

DoWithDefaultRetry executes the provided doFn as long as it returns an error or until a timeout is hit. It applies exponential backoff wait of DefaultBackoffTime * 2^n before nth retry of doFn. In case the calculated backoff is longer than DefaultMaxBackoffTime, the DefaultMaxBackoffTime is applied.

func DoWithRetry

func DoWithRetry(
	backoffTime time.Duration,
	backoffMax time.Duration,
	timeout time.Duration,
	doFn func(ctx context.Context) error,
) error

DoWithRetry executes the provided doFn as long as it returns an error or until a timeout is hit. It applies exponential backoff wait of backoffTime * 2^n before nth retry of doFn. In case the calculated backoff is longer than backoffMax, the backoffMax wait is applied.

Types

This section is empty.

Jump to

Keyboard shortcuts

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