circuit

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCircuitOpen is returned when the circuit breaker is in the Open state.
	ErrCircuitOpen = errors.New("circuit breaker is open")
)

Functions

This section is empty.

Types

type Breaker

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

Breaker implements a circuit breaker state machine.

func New

func New(cfg Config) *Breaker

New returns a new Breaker with the provided configuration.

func (*Breaker) Execute

func (b *Breaker) Execute(action func() error) error

Execute wraps an action with the circuit breaker logic.

func (*Breaker) State

func (b *Breaker) State() State

State returns the current state of the breaker.

type Config

type Config struct {
	// FailureThreshold is the number of failures before the circuit opens.
	FailureThreshold uint
	// ResetTimeout is the duration to wait before transitioning from Open to Half-Open.
	ResetTimeout time.Duration
}

Config defines the configuration for the circuit breaker.

type State

type State int

State represents the current state of the circuit breaker.

const (
	StateClosed State = iota
	StateOpen
	StateHalfOpen
)

Jump to

Keyboard shortcuts

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