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

Byte-budget semaphore for rate limiting by payload size.

Tracks a shared byte budget across concurrent callers. Acquisitions can push
the budget negative to allow in-flight work to complete; new acquisitions
block while the budget is negative and resume once releases bring it back
to a non-negative value.

# `t`

```elixir
@type t() :: pid()
```

# `acquire`

```elixir
@spec acquire(t(), non_neg_integer()) :: :ok
```

Acquire bytes from the semaphore, blocking while the budget is negative.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `release`

```elixir
@spec release(t(), non_neg_integer()) :: :ok
```

Release bytes back to the semaphore.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Start a BytesSemaphore with the given byte budget.

# `with_bytes`

```elixir
@spec with_bytes(t(), non_neg_integer(), (-&gt; result)) :: result when result: any()
```

Execute `fun` while holding the requested byte budget.

---

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