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

Weighted semaphore with blocking acquire and negative budget allowance.

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

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

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

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

Acquire weight, blocking when budget is negative.

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

Returns a specification to start this module under a supervisor.

See `Supervisor`.

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

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

Release weight back to the semaphore.

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

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

Start a weighted semaphore with the given max weight.

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

```elixir
@spec try_acquire(t(), non_neg_integer()) :: :ok | {:error, :unavailable}
```

Attempt to acquire weight without blocking.

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

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

Execute `fun` while holding the requested weight.

---

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