# `Foundation.CircuitBreaker`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L1)

Circuit breaker state machine for resilient calls.

# `state`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L17)

```elixir
@type state() :: :closed | :open | :half_open
```

# `t`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L19)

```elixir
@type t() :: %Foundation.CircuitBreaker{
  failure_count: non_neg_integer(),
  failure_threshold: pos_integer(),
  half_open_calls: non_neg_integer(),
  half_open_max_calls: pos_integer(),
  name: String.t(),
  opened_at: integer() | nil,
  reset_timeout_ms: pos_integer(),
  state: state()
}
```

# `allow_request?`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L47)

```elixir
@spec allow_request?(t()) :: boolean()
```

Check if a request should be allowed.

# `call`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L163)

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

Execute a function through the circuit breaker.

# `new`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L34)

```elixir
@spec new(
  String.t(),
  keyword()
) :: t()
```

Create a new circuit breaker.

# `record_failure`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L113)

```elixir
@spec record_failure(t()) :: t()
```

Record a failed call.

# `record_ignored`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L145)

```elixir
@spec record_ignored(t()) :: t()
```

Ignore a call result without changing breaker health.

This is useful for outcomes such as rate-limits where callers want shared
coordination, but do not want the circuit breaker to count the result as a
success or a failure.

# `record_success`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L96)

```elixir
@spec record_success(t()) :: t()
```

Record a successful call.

# `reset`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L185)

```elixir
@spec reset(t()) :: t()
```

Reset the circuit breaker to a closed state.

# `state`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/circuit_breaker.ex#L80)

```elixir
@spec state(t()) :: state()
```

Get the current circuit breaker state.

---

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