pub struct ConcurrentLimiter { /* private fields */ }Expand description
Concurrent request limiter.
Limits the number of simultaneous in-flight requests per key. Unlike rate limiting, this tracks active requests that haven’t completed yet.
§Example
ⓘ
use oc_ratelimit_advanced::ConcurrentLimiter;
let limiter = ConcurrentLimiter::new(10); // Max 10 concurrent requests
// Acquire a permit
if let Some(permit) = limiter.try_acquire("user:123") {
// Process request...
// Permit is automatically released when dropped
}Implementations§
Source§impl ConcurrentLimiter
impl ConcurrentLimiter
Sourcepub fn try_acquire(&self, key: &str) -> Option<ConcurrentPermit>
pub fn try_acquire(&self, key: &str) -> Option<ConcurrentPermit>
Try to acquire a permit for the given key.
Returns Some(ConcurrentPermit) if successful, None if at limit.
The permit automatically releases when dropped.
Sourcepub async fn acquire(&self, key: &str) -> ConcurrentPermit
pub async fn acquire(&self, key: &str) -> ConcurrentPermit
Acquire a permit, waiting if necessary.
Sourcepub async fn acquire_timeout(
&self,
key: &str,
timeout: Duration,
) -> Option<ConcurrentPermit>
pub async fn acquire_timeout( &self, key: &str, timeout: Duration, ) -> Option<ConcurrentPermit>
Acquire a permit with a timeout.
Sourcepub fn current_count(&self, key: &str) -> u32
pub fn current_count(&self, key: &str) -> u32
Get the current count of active requests for a key.
Sourcepub fn max_concurrent(&self) -> u32
pub fn max_concurrent(&self) -> u32
Get the maximum concurrent requests allowed.
Trait Implementations§
Source§impl Clone for ConcurrentLimiter
impl Clone for ConcurrentLimiter
Auto Trait Implementations§
impl Freeze for ConcurrentLimiter
impl !RefUnwindSafe for ConcurrentLimiter
impl Send for ConcurrentLimiter
impl Sync for ConcurrentLimiter
impl Unpin for ConcurrentLimiter
impl !UnwindSafe for ConcurrentLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more