pub struct Limiter { /* private fields */ }Expand description
A bounded concurrency limiter.
Cheap to clone (the semaphore is wrapped in an Arc); typically built
once per process and shared across the analyzer.
Implementations§
Source§impl Limiter
impl Limiter
Sourcepub fn new(max_concurrent: usize) -> Self
pub fn new(max_concurrent: usize) -> Self
Build a limiter that allows at most max_concurrent in-flight
requests. max_concurrent = 0 is allowed by the type system but
makes every acquire await forever; callers are expected to set a
positive value from LlmConfig::max_concurrent (default 3).
Sourcepub async fn acquire(&self) -> LimiterGuard<'_>
pub async fn acquire(&self) -> LimiterGuard<'_>
Acquire a slot. The slot is held until the returned guard is dropped.
Backpressure is the entire job: callers await, and once K requests
are in flight, the next one queues here until one of the holders
drops its guard.
Sourcepub fn available(&self) -> usize
pub fn available(&self) -> usize
The number of slots currently available for acquisition.
Reflects the configured maximum before any acquisition, decreases by one per held guard, and returns to the maximum once every guard has been dropped. Test-only - exposed via the API so tests can pin the behaviour without reaching into the semaphore.