Versions in this module Expand all Collapse all v1 v1.0.0 Aug 25, 2026 Changes in this version + const MaxBudgetCapacity + const MaxHedges + const MaxResourceLength + var ErrInvalidBudget = errors.New("hedge: invalid budget") + var ErrInvalidPolicy = errors.New("hedge: invalid policy") + type Attempt func(context.Context) (T, error) + type AttemptFactory interface + NewAttempt func(context.Context, AttemptInfo) (Attempt[T], string, error) + type AttemptFactoryFunc func(AttemptInfo) (Attempt[T], string, error) + func (function AttemptFactoryFunc[T]) NewAttempt(_ context.Context, info AttemptInfo) (Attempt[T], string, error) + type AttemptInfo struct + Delay time.Duration + Hedge bool + Ordinal uint + type AttemptResult struct + ContextErr error + Err error + Hedge bool + Ordinal uint + Value T + type Budget interface + Capacity func() uint + TryAcquire func(resource string) (Permit, bool) + type CanceledError struct + func (err *CanceledError) Error() string + func (err *CanceledError) Unwrap() error + type Classification uint8 + const ClassificationCanceled + const ClassificationFailure + const ClassificationSuccess + const ClassificationTerminal + type Classifier interface + Classify func(context.Context, AttemptResult[T]) (Classification, error) + type ClassifyFunc func(context.Context, AttemptResult[T]) (Classification, error) + func (function ClassifyFunc[T]) Classify(ctx context.Context, result AttemptResult[T]) (Classification, error) + type CleanupError struct + Failures uint + func (err *CleanupError) Error() string + type Clock interface + NewTimer func(time.Duration) Timer + Now func() time.Time + WithTimeout func(context.Context, time.Duration) (context.Context, context.CancelFunc) + type Config struct + AttemptTimeout time.Duration + Budget Budget + Classifier Classifier[T] + CleanupTimeout time.Duration + Clock Clock + Delay time.Duration + Disposer Disposer[T] + DynamicDelay DelayFunc + FactoryFailureMode FactoryFailureMode + MaxHedges uint + Observer Observer + ReplaySafe bool + Resource string + Schedule []time.Duration + TotalTimeout time.Duration + UseResilienceBudget bool + type DeadlineError struct + func (*DeadlineError) Error() string + func (*DeadlineError) Unwrap() error + type DelayFunc func(DelayInput) (time.Duration, error) + type DelayInput struct + Hedge uint + Previous time.Duration + type DisposeFunc func(context.Context, T) error + func (function DisposeFunc[T]) Dispose(ctx context.Context, value T) error + type Disposer interface + Dispose func(context.Context, T) error + type ExecutionError struct + func (err *ExecutionError) Error() string + func (err *ExecutionError) Unwrap() error + type FactoryFailureMode uint8 + const FactoryFailureContinue + const FactoryFailureStop + type Failure struct + Classification Classification + Delay time.Duration + Duration time.Duration + Endpoint string + Hedge bool + Ordinal uint + type Observation struct + Classification Classification + Delay time.Duration + Duration time.Duration + Endpoint string + Loser bool + Ordinal uint + Outcome Outcome + Resource string + Winner bool + type Observer interface + TryObserve func(Observation) bool + type Outcome uint8 + const OutcomeAllAttemptsFailed + const OutcomeAttemptCompleted + const OutcomeBudgetDenied + const OutcomeCallerCanceled + const OutcomeCleanupFailed + const OutcomeHedgeStarted + const OutcomeNoHedgeNeeded + const OutcomeTotalDeadline + const OutcomeWinnerSelected + func (outcome Outcome) String() string + type OutstandingBudget struct + func NewOutstandingBudget(limit uint) (*OutstandingBudget, error) + func (budget *OutstandingBudget) Capacity() uint + func (budget *OutstandingBudget) Outstanding() uint64 + func (budget *OutstandingBudget) TryAcquire(_ string) (Permit, bool) + type Permit interface + Release func() + type Policy struct + func NewPolicy[T any](config Config[T]) (*Policy[T], error) + type RealClock struct + func (RealClock) NewTimer(delay time.Duration) Timer + func (RealClock) Now() time.Time + func (RealClock) WithTimeout(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc) + type Reason uint8 + const ReasonAllAttemptsFailed + const ReasonBudgetFailure + const ReasonCallerCanceled + const ReasonDelayFailure + const ReasonFactoryFailure + const ReasonNoHedgeNeeded + const ReasonTerminalFailure + const ReasonTotalDeadline + const ReasonWinnerSelected + type Report struct + AttemptsStarted uint + BudgetDenied uint + Failures []Failure + HedgesStarted uint + Reason Reason + SelectedOrdinal uint + WinnerOrdinal uint + func Do[T any](ctx context.Context, policy *Policy[T], factory AttemptFactory[T]) (T, Report, error) + func (report Report) Wait(ctx context.Context) error + type Timer interface + C func() <-chan time.Time + Stop func() bool