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

Layered dispatch limiter combining concurrency, throttling, and byte budgets.

# `option`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/dispatch.ex#L33)

```elixir
@type option() ::
  {:name, GenServer.name()}
  | {:key, term()}
  | {:registry, Foundation.Semaphore.Counting.registry()}
  | {:limiter, Foundation.RateLimit.BackoffWindow.limiter()}
  | {:concurrency, pos_integer()}
  | {:throttled_concurrency, pos_integer()}
  | {:byte_budget, pos_integer()}
  | {:backoff_window_ms, pos_integer()}
  | {:byte_penalty_multiplier, pos_integer()}
  | {:acquire_backoff, Foundation.Backoff.Policy.t() | keyword()}
  | {:sleep_fun, (non_neg_integer() -&gt; any())}
```

# `snapshot`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/dispatch.ex#L22)

```elixir
@type snapshot() :: %{
  concurrency: %{name: term(), limit: pos_integer()},
  throttled: %{name: term(), limit: pos_integer()},
  bytes: Foundation.Semaphore.Weighted.t(),
  backoff_active?: boolean(),
  acquire_backoff: Foundation.Backoff.Policy.t(),
  registry: Foundation.Semaphore.Counting.registry(),
  sleep_fun: (non_neg_integer() -&gt; any()),
  byte_penalty_multiplier: pos_integer()
}
```

# `child_spec`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/dispatch.ex#L6)

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `set_backoff`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/dispatch.ex#L65)

```elixir
@spec set_backoff(GenServer.server(), non_neg_integer()) :: :ok
```

Set a backoff window (in milliseconds) and mark the dispatch as recently throttled.

# `snapshot`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/dispatch.ex#L73)

```elixir
@spec snapshot(GenServer.server()) :: snapshot()
```

Return a snapshot of the dispatch state.

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

```elixir
@spec start_link([option()]) :: GenServer.on_start()
```

# `with_rate_limit`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/dispatch.ex#L56)

```elixir
@spec with_rate_limit(GenServer.server(), non_neg_integer(), (-&gt; result)) :: result
when result: any()
```

Execute `fun` while holding the layered dispatch semaphores.

---

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