Optional client-side sliding-window rate limiter.
Use it to stay within the public detalji_subjekta limit of 6 requests/minute:
{:ok, _} = SudregEx.RateLimiter.start_link(name: :sudreg_limiter)
:ok = SudregEx.RateLimiter.acquire(:sudreg_limiter)
SudregEx.Api.detalji_subjekta(client, tip_identifikatora: "oib", identifikator: oib)Not started by default — start one yourself (e.g. in your supervision tree).
acquire/1 blocks the caller until a slot frees; the GenServer itself never
sleeps, so admission decisions stay responsive.
Under many concurrent callers, waiters wake together and re-contend; admission
stays correct (never more than limit per window) but a retry storm is
possible — a non-issue for the single-consumer detalji_subjekta case.
Summary
Functions
Blocks until a request slot is free within the window, then returns :ok.
Returns a specification to start this module under a supervisor.
Starts the limiter. Options: :name (default SudregEx.RateLimiter),
:limit (default 6), :window_ms (default 60_000).
Functions
@spec acquire(GenServer.server()) :: :ok
Blocks until a request slot is free within the window, then returns :ok.
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec start_link(keyword()) :: GenServer.on_start()
Starts the limiter. Options: :name (default SudregEx.RateLimiter),
:limit (default 6), :window_ms (default 60_000).