Versions in this module Expand all Collapse all v0 v0.50.0 Mar 19, 2026 Changes in this version + var ErrOpen = errors.New("cb: circuit breaker is open") + func ConsecutiveFailures(n int) func(Snapshot) bool + func MapErr[T, R any](fn func(context.Context, T) (R, error), mapper func(error) error) func(context.Context, T) (R, error) + func OnErr[T, R any](fn func(context.Context, T) (R, error), onErr func(error)) func(context.Context, T) (R, error) + func Retry[T, R any](maxAttempts int, backoff Backoff, shouldRetry func(error) bool, ...) func(context.Context, T) (R, error) + func ThrottleWeighted[T, R any](capacity int, cost func(T) int, fn func(context.Context, T) (R, error)) func(context.Context, T) (R, error) + func Throttle[T, R any](n int, fn func(context.Context, T) (R, error)) func(context.Context, T) (R, error) + func WithBreaker[T, R any](b *Breaker, fn func(context.Context, T) (R, error)) func(context.Context, T) (R, error) + type Backoff func(n int) time.Duration + func ConstantBackoff(delay time.Duration) Backoff + func ExponentialBackoff(initial time.Duration) Backoff + type Breaker struct + func NewBreaker(cfg BreakerConfig) *Breaker + func (b *Breaker) Snapshot() Snapshot + type BreakerConfig struct + Clock func() time.Time + OnStateChange func(Transition) + ReadyToTrip func(Snapshot) bool + ResetTimeout time.Duration + ShouldCount func(error) bool + type BreakerState int + const StateClosed + const StateHalfOpen + const StateOpen + func (s BreakerState) String() string + type DebounceOption func(*debounceConfig) + func MaxWait(d time.Duration) DebounceOption + type Debouncer struct + func NewDebouncer[T any](wait time.Duration, fn func(T), opts ...DebounceOption) *Debouncer[T] + func (d *Debouncer[T]) Call(v T) + func (d *Debouncer[T]) Cancel() bool + func (d *Debouncer[T]) Close() + func (d *Debouncer[T]) Flush() bool + type Snapshot struct + ConsecutiveFailures int + Failures int + OpenedAt time.Time + Rejected int + State BreakerState + Successes int + type Transition struct + At time.Time + From BreakerState + To BreakerState