try

package
v1.8.4 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

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

nolint: ireturn

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.

To avoid any deadlock, the function will stop if the errors is context.Canceled or context.DeadlineExceeded.

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.

To avoid any deadlock, the function will stop if the errors is context.Canceled or context.DeadlineExceeded.

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.

To avoid any deadlock, the function will stop if the errors is context.Canceled.

func DoWithResult

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

DoWithResult tries a function and returns a result.

To avoid any deadlock, the function will stop if the errors is context.Canceled or context.DeadlineExceeded.

func GenerateDelays added in v1.8.4

func GenerateDelays(
	tries int,
	delay time.Duration,
	multiplier time.Duration,
	maxBackoff time.Duration,
) []time.Duration

GenerateDelays generates a slice of delays for exponential backoff.

Types

This section is empty.

Jump to

Keyboard shortcuts

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