pub struct RequestLimiter {
semaphore: Arc<Semaphore>,
}Expand description
Limits unfinished original requests independently of their number of submissions.
Acquire once for each original request, then clone its permit into all of that request’s submissions. Capacity is released when the last owner drops it.
Fields§
§semaphore: Arc<Semaphore>Implementations§
Source§impl RequestLimiter
impl RequestLimiter
Sourcepub fn try_new(max_inflight_requests: usize) -> Option<Self>
pub fn try_new(max_inflight_requests: usize) -> Option<Self>
Returns None if the limit is zero or exceeds Tokio’s supported semaphore capacity.
Sourcepub async fn acquire(&self) -> Result<Arc<OwnedSemaphorePermit>, AcquireError>
pub async fn acquire(&self) -> Result<Arc<OwnedSemaphorePermit>, AcquireError>
Waits for one request slot and returns a permit shared by its submissions.
Cancelling a pending acquisition does not consume a slot. Once acquired, callers must retain the permit until every submission has finished, even if the original caller stops waiting for its response.
Trait Implementations§
Source§impl Clone for RequestLimiter
impl Clone for RequestLimiter
Source§fn clone(&self) -> RequestLimiter
fn clone(&self) -> RequestLimiter
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for RequestLimiter
impl !UnwindSafe for RequestLimiter
impl Freeze for RequestLimiter
impl Send for RequestLimiter
impl Sync for RequestLimiter
impl Unpin for RequestLimiter
impl UnsafeUnpin for RequestLimiter
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