pub struct AsyncWeightedSemaphore { /* private fields */ }Expand description
A semaphore admitting weighted permits under a runtime-adjustable capacity limit.
Acquisition waits until the in-flight weight plus the requested weight fits under the current limit. The limit can be raised or lowered while permits are held; a single permit whose weight exceeds the limit is admitted when nothing else is in flight, so it cannot deadlock.
Implementations§
Source§impl AsyncWeightedSemaphore
impl AsyncWeightedSemaphore
Sourcepub fn new(limit: u64) -> Arc<Self> ⓘ
pub fn new(limit: u64) -> Arc<Self> ⓘ
Create a semaphore with the given initial capacity limit.
Sourcepub fn set_limit(&self, new_limit: u64)
pub fn set_limit(&self, new_limit: u64)
Change the capacity limit. Raising it wakes waiters to re-check; lowering it applies backpressure, waiting acquisitions until in-flight weight drains.
Sourcepub fn raise_limit(&self, candidate: u64) -> u64
pub fn raise_limit(&self, candidate: u64) -> u64
Raise the limit to at least candidate, never lowering it; wakes waiters if raised.
Returns the previous limit so callers can detect/log an actual raise.
Monotonic: a candidate at or below the current limit is a no-op.
Sourcepub fn try_acquire(
self: &Arc<Self>,
weight: u64,
) -> Option<AsyncWeightedSemaphoreGuard>
pub fn try_acquire( self: &Arc<Self>, weight: u64, ) -> Option<AsyncWeightedSemaphoreGuard>
Try to acquire weight units without waiting.
Never blocks. On success the guard holds the weight until dropped. A zero-weight request always succeeds and accounts nothing.
Sourcepub async fn acquire(
self: &Arc<Self>,
weight: u64,
) -> AsyncWeightedSemaphoreGuard
pub async fn acquire( self: &Arc<Self>, weight: u64, ) -> AsyncWeightedSemaphoreGuard
Acquire weight units, waiting until they fit under the current limit.
Blocks until enough weight drains (or the limit is raised). The returned guard holds the weight until dropped. No deadlock timeout: an over-limit request is admitted only when nothing else is in flight.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AsyncWeightedSemaphore
impl RefUnwindSafe for AsyncWeightedSemaphore
impl Send for AsyncWeightedSemaphore
impl Sync for AsyncWeightedSemaphore
impl Unpin for AsyncWeightedSemaphore
impl UnsafeUnpin for AsyncWeightedSemaphore
impl UnwindSafe for AsyncWeightedSemaphore
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more