# `Tinkex.CircuitBreaker.Registry`
[🔗](https://github.com/North-Shore-AI/tinkex/blob/v0.4.0/lib/tinkex/circuit_breaker/registry.ex#L1)

ETS-based registry for circuit breaker state.

Circuit breakers are identified by endpoint names and can be shared across
processes in the same node. Updates are versioned to avoid lost-update races
under concurrency.

## Usage

    # Initialize the registry (typically in Application.start/2)
    CircuitBreaker.Registry.init()

    # Execute a call through a circuit breaker
    case CircuitBreaker.Registry.call("sampling-endpoint", fn ->
      Tinkex.API.Sampling.sample_async(request, opts)
    end) do
      {:ok, result} -> handle_success(result)
      {:error, :circuit_open} -> {:error, "Service temporarily unavailable"}
      {:error, reason} -> {:error, reason}
    end

    # Check circuit state
    CircuitBreaker.Registry.state("sampling-endpoint")
    # => :closed | :open | :half_open

    # Reset a specific circuit
    CircuitBreaker.Registry.reset("sampling-endpoint")

# `call`

```elixir
@spec call(String.t(), (-&gt; result), keyword()) :: result | {:error, :circuit_open}
when result: term()
```

Execute a function through a named circuit breaker.

Creates the circuit breaker if it doesn't exist.

## Options

- `:failure_threshold` - Failures before opening (default: 5)
- `:reset_timeout_ms` - Open duration before half-open (default: 30,000)
- `:half_open_max_calls` - Calls allowed in half-open (default: 1)
- `:success?` - Custom success classifier function

# `delete`

```elixir
@spec delete(String.t()) :: :ok
```

Delete a circuit breaker from the registry.

# `init`

```elixir
@spec init() :: :ok
```

Initialize the circuit breaker registry.

Creates the ETS table if it doesn't exist. Safe to call multiple times.

# `list`

```elixir
@spec list() :: [{String.t(), Tinkex.CircuitBreaker.state()}]
```

List all circuit breakers and their states.

# `reset`

```elixir
@spec reset(String.t()) :: :ok
```

Reset a circuit breaker to closed state.

# `state`

```elixir
@spec state(String.t()) :: Tinkex.CircuitBreaker.state()
```

Get the current state of a circuit breaker.

Returns `:closed` if the circuit breaker doesn't exist.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
