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

Blocking semaphore wrapper used to cap concurrent sampling retry executions.

Uses the `semaphore` library's global ETS-backed semaphore. Each distinct
`max_connections` value maps to its own semaphore name.

# `semaphore_name`

```elixir
@type semaphore_name() :: {:tinkex_retry, term(), pos_integer()}
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `get_semaphore`

```elixir
@spec get_semaphore(pos_integer()) :: semaphore_name()
```

Return the semaphore name for a given max_connections.

# `get_semaphore`

```elixir
@spec get_semaphore(term(), pos_integer()) :: semaphore_name()
```

Return the semaphore name for a given key and max_connections.

# `start_link`

Start the semaphore supervisor and underlying semaphore server.

# `with_semaphore`

```elixir
@spec with_semaphore(pos_integer(), (-&gt; term())) :: term()
```

Execute `fun` while holding the semaphore for `max_connections`.
Blocks until capacity is available.

# `with_semaphore`

```elixir
@spec with_semaphore(pos_integer(), keyword(), (-&gt; term())) :: term()
@spec with_semaphore(term(), pos_integer(), (-&gt; term())) :: term()
```

Execute `fun` while holding a keyed semaphore. Callers can provide a unique
key to isolate capacity between clients even when max_connections matches.

# `with_semaphore`

```elixir
@spec with_semaphore(term(), pos_integer(), keyword(), (-&gt; term())) :: term()
```

---

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