pub struct ConnectionSemaphore { /* private fields */ }Expand description
Wraps an optional global and an optional factor-specific semaphore.
Implementations§
Source§impl ConnectionSemaphore
impl ConnectionSemaphore
Sourcepub fn new(
global: Option<Arc<Semaphore>>,
factor_specific_limit: Option<usize>,
factor: &'static str,
wait_timeout: Option<Duration>,
) -> Self
pub fn new( global: Option<Arc<Semaphore>>, factor_specific_limit: Option<usize>, factor: &'static str, wait_timeout: Option<Duration>, ) -> Self
Creates a new ConnectionSemaphore.
global is an optional semaphore shared across factors; factor_specific_limit
is an optional permit limit for this specific factor. If either is None, that level of
limiting is disabled. factor is a label used in emitted telemetry, and wait_timeout is
an optional duration to wait for a permit before giving up and returning an error.
Sourcepub async fn acquire(&self) -> Result<ConnectionPermit>
pub async fn acquire(&self) -> Result<ConnectionPermit>
Acquire both configured semaphore slots, returning a permit that holds them until dropped.
When both a global and a factor-specific semaphore are configured, this method acquires factor-specific first, then global, ensuring the global permit is never held while blocking on a factor-specific backlog.
If wait_timeout is configured and the permits cannot be acquired within
that duration, an error is returned.
Sourcepub fn try_acquire(&self) -> Option<ConnectionPermit>
pub fn try_acquire(&self) -> Option<ConnectionPermit>
Attempt to acquire both configured slots without waiting.
Returns None if either semaphore is exhausted.
If the global permit is acquired but the factor-specific permit is not
available, the global permit is released before returning None.
Trait Implementations§
Source§impl Clone for ConnectionSemaphore
impl Clone for ConnectionSemaphore
Source§fn clone(&self) -> ConnectionSemaphore
fn clone(&self) -> ConnectionSemaphore
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ConnectionSemaphore
impl !UnwindSafe for ConnectionSemaphore
impl Freeze for ConnectionSemaphore
impl Send for ConnectionSemaphore
impl Sync for ConnectionSemaphore
impl Unpin for ConnectionSemaphore
impl UnsafeUnpin for ConnectionSemaphore
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request