retry

package
v0.0.104-dev Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Call

type Call[T any] func(ctx context.Context, isRetry bool) (T, error)

type Hedged

type Hedged[T any] struct {
	// The function must be thread-safe because multiple instances may be running
	// concurrently. The function must return as soon as possible after context
	// cancellation, otherwise the speculation makes no sense.
	//
	// The function argument indicates whether this is a speculative retry attempt.
	Call    Call[T]
	Trigger <-chan time.Time

	// FailFast specifies how a failure is handled. If it is set to true:
	//  - the result received first is returned, regardless of anything.
	//  - if Call fails before the trigger fires, it won't be retried.
	FailFast bool

	// Throttler executes call retries. Optional.
	Throttler
}

Hedged executes Call with a speculative retry after trigger fires if it has not returned earlier.

By default, if one of the attempts fails, another one is not canceled. In this case the speculative attempt will not start until the trigger fires. For more granular control, use FailFast.

func (Hedged[T]) Do

func (s Hedged[T]) Do(ctx context.Context) (T, error)

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter limits the number of tasks executed. Once the limit is reached, no more runs will be done.

func NewLimiter

func NewLimiter(n int64) *Limiter

func (*Limiter) Run

func (l *Limiter) Run(f func())

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter implements Throttler using golang.org/x/time/rate with the given rate (ops per second) and burst size.

func NewRateLimiter

func NewRateLimiter(ratePerSec float64, burst int) *RateLimiter

func (*RateLimiter) Run

func (r *RateLimiter) Run(f func())

type Throttler

type Throttler interface {
	Run(func())
}

Jump to

Keyboard shortcuts

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