try

package
v1.8.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package try provides a set of functions to retry a function with a delay.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(
	tries int,
	delay time.Duration,
	fn func() error,
) (err error)

Do tries a function with a delay.

func DoExponentialBackoff

func DoExponentialBackoff(
	tries int,
	delay time.Duration,
	multiplier time.Duration,
	maxBackoff time.Duration,
	fn func() error,
) (err error)

DoExponentialBackoff tries a function with exponential backoff.

func DoExponentialBackoffWithContextAndResult added in v0.4.0

func DoExponentialBackoffWithContextAndResult[T any](
	parent context.Context,
	tries int,
	delay time.Duration,
	multiplier int,
	maxBackoff time.Duration,
	fn func(ctx context.Context) (T, error),
) (result T, err error)

DoExponentialBackoffWithContextAndResult performs an exponential backoff with context and returns a result

nolint: ireturn

func DoExponentialBackoffWithResult

func DoExponentialBackoffWithResult[T any](
	tries int,
	delay time.Duration,
	multiplier int,
	maxBackoff time.Duration,
	fn func() (T, error),
) (result T, err error)

DoExponentialBackoffWithResult performs an exponential backoff and return a result.

nolint: ireturn

func DoWithContextTimeout

func DoWithContextTimeout(
	parent context.Context,
	tries int,
	delay time.Duration,
	timeout time.Duration,
	fn func(ctx context.Context, try int) error,
) (err error)

DoWithContextTimeout tries a function with context and timeout.

func DoWithContextTimeoutWithResult

func DoWithContextTimeoutWithResult[T any](
	parent context.Context,
	tries int,
	delay time.Duration,
	timeout time.Duration,
	verbose bool,
	fn func(ctx context.Context, try int) (T, error),
) (result T, err error)

DoWithContextTimeoutWithResult performs a function with context and returns a result.

nolint: ireturn

func DoWithResult

func DoWithResult[T any](
	tries int,
	delay time.Duration,
	fn func() (T, error),
) (result T, err error)

DoWithResult tries a function and returns a result.

nolint: ireturn

Types

This section is empty.

Jump to

Keyboard shortcuts

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