backoff

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Unlicense Imports: 2 Imported by: 1

README

Exponential Backoff

GoDoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Retry

func Retry(strategy Strategy, fn Func) error

Retry keeps trying the fn until it returns false or no error. It will pause between retries according to backoff strategy.

func RetryWithContext added in v0.2.0

func RetryWithContext(ctx context.Context, strategy Strategy, fn Func) error

RetryWithContext keeps trying the fn until it returns false or no error. It will pause between retries according to backoff strategy. If context is canceled during a pause context error is returned without re-calling provided fn.

Types

type Func

type Func func(attempt uint, reset func()) (retry bool, err error)

Func represents functions that can be retried, reset param shouldn't be called in new goroutine.

type Strategy

type Strategy interface {
	// Pause returns duration of the next pause, according to the attempt number.
	Pause(attempt uint) time.Duration
}

Strategy is a backoff methodology for retrying an operation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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