# `Foundation.Semaphore.Counting`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L1)

ETS-backed counting semaphore.

# `name`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L13)

```elixir
@type name() :: term()
```

# `registry`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L12)

```elixir
@type registry() :: :ets.tid() | atom()
```

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

```elixir
@spec acquire(name(), pos_integer()) :: boolean()
```

Acquire a semaphore in the default registry.

# `acquire`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L39)

```elixir
@spec acquire(registry(), name(), pos_integer()) :: boolean()
```

Acquire a semaphore in the provided registry.

# `acquire_blocking`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L107)

```elixir
@spec acquire_blocking(
  registry(),
  name(),
  pos_integer(),
  Foundation.Backoff.Policy.t(),
  keyword()
) ::
  :ok
```

Acquire a semaphore, retrying with backoff until available.

# `count`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L76)

```elixir
@spec count(registry(), name()) :: non_neg_integer()
```

Get the current count for a semaphore.

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

```elixir
@spec default_registry() :: registry()
```

Return the default registry (anonymous ETS table).

# `new_registry`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L27)

```elixir
@spec new_registry(keyword()) :: registry()
```

Create a new registry. Use `name: :my_table` for a named ETS table.

# `release`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L60)

```elixir
@spec release(name()) :: :ok
```

Release a semaphore in the default registry.

# `release`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L66)

```elixir
@spec release(registry(), name()) :: :ok
```

Release a semaphore in the provided registry.

# `try_acquire`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L54)

```elixir
@spec try_acquire(registry(), name(), pos_integer()) :: boolean()
```

Attempt to acquire a semaphore without blocking.

# `with_acquire`
[🔗](https://github.com/nshkrdotcom/foundation/blob/v0.2.1/lib/foundation/semaphore/counting.ex#L91)

```elixir
@spec with_acquire(registry(), name(), pos_integer(), (-&gt; result)) ::
  {:ok, result} | {:error, :max}
when result: any()
```

Execute a function while holding a semaphore.

---

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