Versions in this module Expand all Collapse all v1 v1.0.0 Aug 25, 2026 Changes in this version + const MaxIdentityLength + var ErrBudgetAlreadyAttached = errors.New("resilience: budget already attached") + var ErrBudgetClosed = errors.New("resilience: budget scope closed") + var ErrBudgetRejected = errors.New("resilience: work budget rejected") + var ErrBudgetScopeMismatch = errors.New("resilience: budget scope mismatch") + var ErrBudgetScopeRequired = errors.New("resilience: budget scope required") + var ErrIgnored = errors.New("resilience: ignored") + var ErrInvalidAttempt = errors.New("resilience: invalid attempt") + var ErrInvalidComposition = errors.New("resilience: invalid composition") + var ErrInvalidMetadata = errors.New("resilience: invalid metadata") + var ErrLocalRejection = errors.New("resilience: local rejection") + var ErrNilOperation = errors.New("resilience: nil operation") + var ErrPermitCompleted = errors.New("resilience: permit already completed") + var ErrPermitExpired = errors.New("resilience: permit expired") + var ErrPolicyFailure = errors.New("resilience: policy failure") + func AdmitAttempt(ctx context.Context, origin AttemptOrigin, parent uint64, startedAt time.Time) (context.Context, Attempt, Permit, error) + func WithBudgetScope(ctx context.Context, scope WorkBudgetScope) (context.Context, error) + type Attempt struct + Ordinal uint64 + Origin AttemptOrigin + ParentOrdinal uint64 + StartedAt time.Time + func AttemptFromContext(ctx context.Context) (Attempt, bool) + func NewAttempt(ordinal uint64, origin AttemptOrigin, parent uint64, startedAt time.Time) (Attempt, error) + type AttemptOrigin string + const OriginHedge + const OriginOriginal + const OriginRetry + type Budget struct + func NewBudget(config BudgetConfig) (*Budget, error) + func (budget *Budget) Start(ctx context.Context, metadata Metadata) (WorkBudgetScope, context.Context, error) + type BudgetConfig struct + AdditionalWindow time.Duration + Clock Clock + MaxAdditionalPerExecution uint64 + MaxAdditionalPerWindow uint64 + MaxConcurrentAdditional uint64 + MaxResources int + PermitTTL time.Duration + type BudgetRejectionError struct + Reason RejectionReason + Snapshot BudgetSnapshot + func (err *BudgetRejectionError) Error() string + func (err *BudgetRejectionError) Unwrap() error + type BudgetScope struct + func (scope *BudgetScope) Acquire(ctx context.Context, attempt Attempt) (Permit, error) + func (scope *BudgetScope) Close() error + func (scope *BudgetScope) Matches(metadata Metadata) bool + func (scope *BudgetScope) Snapshot() BudgetSnapshot + type BudgetSnapshot struct + AdditionalActive uint64 + AdditionalAdmitted uint64 + AdditionalRecent uint64 + Closed bool + LogicalID string + Resource string + type Clock interface + Now func() time.Time + type ConfigurationError struct + Field string + Kind error + Reason string + func (err *ConfigurationError) Error() string + func (err *ConfigurationError) Unwrap() error + type Event struct + At time.Time + Attempt Attempt + Kind EventKind + LogicalID string + Policy PolicyID + Reason string + type EventKind string + const EventAttemptCompleted + const EventAttemptStarted + const EventExecutionCanceled + const EventExecutionCompleted + const EventExecutionStarted + const EventPolicyEntered + const EventWorkAdmitted + const EventWorkRejected + type Execution struct + Attempt Attempt + Metadata Metadata + func (execution Execution) Emit(kind EventKind, policy PolicyID, reason string) + func (execution Execution) WithAttempt(attempt Attempt) (Execution, error) + type Executor struct + func NewExecutor[T any](policies ...Policy[T]) (Executor[T], error) + func (executor Executor[T]) Execute(ctx context.Context, metadata Metadata, operation Operation[T]) (result Result[T]) + func (executor Executor[T]) Policies() []PolicyDescriptor + func (executor Executor[T]) WithClock(clock Clock) (Executor[T], error) + func (executor Executor[T]) WithObserver(observer Observer, maxEvents int) (Executor[T], error) + func (executor Executor[T]) WithTimeline(maxEvents int) (Executor[T], error) + type IgnoredError struct + Reason string + func (err *IgnoredError) Error() string + func (err *IgnoredError) Unwrap() error + type LocalRejectionError struct + Cause error + Policy PolicyID + Reason string + func (err *LocalRejectionError) Error() string + func (err *LocalRejectionError) Unwrap() []error + type Metadata struct + func NewMetadata(logicalID, operation, resource string) (Metadata, error) + func (metadata Metadata) LogicalID() string + func (metadata Metadata) Operation() string + func (metadata Metadata) Resource() string + type Observer interface + Observe func(Event) + type ObserverFunc func(Event) + func (function ObserverFunc) Observe(event Event) + type Operation func(context.Context, Attempt) (T, error) + type Outcome struct + Attempt Attempt + Kind OutcomeKind + type OutcomeKind string + const OutcomeCancellation + const OutcomeDeadline + const OutcomeIgnored + const OutcomeLocalRejection + const OutcomeOperationFailure + const OutcomePolicyFailure + const OutcomeSuccess + type Permit interface + Complete func() error + type Policy interface + Descriptor func() PolicyDescriptor + Wrap func(Stage[T]) Stage[T] + type PolicyDescriptor struct + ID PolicyID + Repeatable bool + Scope Scope + type PolicyExecutionError struct + Cause error + Policy PolicyID + Stage string + func (err *PolicyExecutionError) Error() string + func (err *PolicyExecutionError) Unwrap() []error + type PolicyID string + type RejectionReason string + const ReasonConcurrentLimit + const ReasonDuplicateWork + const ReasonExecutionLimit + const ReasonOriginalRequired + const ReasonResourceLimit + const ReasonUnknownParent + const ReasonWindowLimit + func RejectionReasonOf(err error) RejectionReason + type Result struct + Err error + Events []Event + Outcome Outcome + Value T + func Failure[T any](value T, err error, attempt Attempt) Result[T] + func Ignored[T any](attempt Attempt, reason string) Result[T] + func LocalRejection[T any](attempt Attempt, policy PolicyID, reason string, cause error) Result[T] + func PolicyFailure[T any](attempt Attempt, policy PolicyID, stage string, cause error) Result[T] + func Success[T any](value T, attempt Attempt) Result[T] + type Scope string + const ScopeAttempt + const ScopeLogical + type Stage func(context.Context, Execution, Operation[T]) Result[T] + type WorkBudget interface + Start func(context.Context, Metadata) (WorkBudgetScope, context.Context, error) + type WorkBudgetScope interface + Acquire func(context.Context, Attempt) (Permit, error) + Close func() error + Matches func(Metadata) bool + Snapshot func() BudgetSnapshot + func BudgetScopeFromContext(ctx context.Context) (WorkBudgetScope, bool) + type WorkPermit struct + func (permit *WorkPermit) Complete() error