retry

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2025 License: AGPL-3.0 Imports: 4 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
}

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)

Jump to

Keyboard shortcuts

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