retry

package
v0.0.0-...-a171562 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PollWithBackoff

func PollWithBackoff(ctx context.Context, cfg PollConfig, f PollWithBackoffCtxFunc, opts ...PollOption) error

PollWithBackoff runs f every duration given by the config.

If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f. It returns when: - context signals done. Context error is returned in this case. - f returns Done

Types

type AttemptResult

type AttemptResult int
const (
	// Continue means there was no error and polling can continue normally.
	Continue AttemptResult = iota
	// ContinueImmediately means there was no error and polling can continue normally.
	ContinueImmediately
	// Backoff means there was a retriable error, so the caller should try later.
	Backoff
	// Done means the polling should stop. There may or may not have been an error.
	Done
)

type BackoffConfig

type BackoffConfig interface {
	Next(clock clock.Clock) time.Duration
	Clone() BackoffConfig
}

func NewExponentialBackoff

func NewExponentialBackoff(initBackoff, maxBackoff, resetDuration time.Duration, backoffFactor, jitter float64) BackoffConfig

type PokeChannel

type PokeChannel chan struct{}

func NewPokeChannel

func NewPokeChannel() PokeChannel

func (PokeChannel) Poke

func (c PokeChannel) Poke()

type PollConfig

type PollConfig struct {
	Interval time.Duration
	Backoff  BackoffConfig
}

type PollOption

type PollOption func(*pollOptions)

func WithClock

func WithClock(c clock.Clock) PollOption

func WithPokeChannel

func WithPokeChannel(c PokeChannel) PollOption

type PollWithBackoffCtxFunc

type PollWithBackoffCtxFunc func(ctx context.Context) (error, AttemptResult)

PollWithBackoffCtxFunc is a function that is called to perform polling. Signature is unusual because AttemptResult must be checked, not the error.

type PollWithBackoffFunc

type PollWithBackoffFunc func() (error, AttemptResult)

PollWithBackoffFunc is a function that is called to perform polling. Signature is unusual because AttemptResult must be checked, not the error.

Jump to

Keyboard shortcuts

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