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<LimitedSemaphore>,
factor_specific: Option<LimitedSemaphore>,
factor: &'static str,
app_id: Arc<str>,
wait_timeout: Option<Duration>,
) -> Self
pub fn new( global: Option<LimitedSemaphore>, factor_specific: Option<LimitedSemaphore>, factor: &'static str, app_id: Arc<str>, wait_timeout: Option<Duration>, ) -> Self
Creates a new ConnectionSemaphore.
global is an optional LimitedSemaphore shared across factors; factor_specific is an
optional LimitedSemaphore for this specific factor. If either is None, that level of
limiting is disabled. factor is a label used in emitted telemetry, app_id identifies
the owning app for tenant-attribution in tracing events, 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> 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