Foundation.Semaphore.Weighted (foundation v0.2.1)

Copy Markdown View Source

Weighted semaphore with blocking acquire and negative budget allowance.

Summary

Functions

Acquire weight, blocking when budget is negative.

Returns a specification to start this module under a supervisor.

Release weight back to the semaphore.

Start a weighted semaphore with the given max weight.

Attempt to acquire weight without blocking.

Execute fun while holding the requested weight.

Types

t()

@type t() :: pid()

Functions

acquire(semaphore, weight)

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

Acquire weight, blocking when budget is negative.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

release(semaphore, weight)

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

Release weight back to the semaphore.

start_link(opts \\ [])

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

Start a weighted semaphore with the given max weight.

try_acquire(semaphore, weight)

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

Attempt to acquire weight without blocking.

with_acquire(semaphore, weight, fun)

@spec with_acquire(t(), non_neg_integer(), (-> result)) :: result when result: any()

Execute fun while holding the requested weight.