Coffrify. Runtime. RateLimit behaviour
(Coffrify v0.9.0)
View Source
Client-side rate limiting. Use to stay below plan caps without hitting 429s.
Two adapters are bundled:
Coffrify.Runtime.RateLimit.TokenBucket— allows bursts up to capacity.Coffrify.Runtime.RateLimit.LeakyBucket— paces requests at a steady drain.
Both are GenServer-based. Pass the PID (or registered name) as
:rate_limiter to Coffrify.new/1. The client calls acquire/1 before
each request.
Summary
Callbacks
Wait until a token is available, then consume it.
Snapshot for observability.
Try to consume a token without waiting.
Functions
Acquire dispatching to the right adapter. Accepts either a PID/name
(assumed TokenBucket) or a {module, pid} tuple. The module must
implement the Coffrify.Runtime.RateLimit behaviour.
Types
@type t() :: GenServer.server()
Any term implementing the limiter behaviour.
Callbacks
Functions
@spec acquire(any()) :: :ok
Acquire dispatching to the right adapter. Accepts either a PID/name
(assumed TokenBucket) or a {module, pid} tuple. The module must
implement the Coffrify.Runtime.RateLimit behaviour.