Tinkex.RetrySemaphore (Tinkex v0.2.2)

View Source

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.

Summary

Functions

Returns a specification to start this module under a supervisor.

Return the semaphore name for a given max_connections.

Return the semaphore name for a given key and max_connections.

Start the semaphore supervisor and underlying semaphore server.

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

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

Types

semaphore_name()

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

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_semaphore(max_connections)

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

Return the semaphore name for a given max_connections.

get_semaphore(key, max_connections)

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

Return the semaphore name for a given key and max_connections.

start_link(opts \\ [])

Start the semaphore supervisor and underlying semaphore server.

with_semaphore(max_connections, fun)

@spec with_semaphore(pos_integer(), (-> term())) :: term()

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

with_semaphore(key, max_connections, fun)

@spec with_semaphore(term(), pos_integer(), (-> 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.