pub struct Semaphore { /* private fields */ }Expand description
A counting semaphore for limiting concurrent access.
Implementations§
Source§impl Semaphore
impl Semaphore
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Returns the number of currently available permits.
Sourcepub fn max_permits(&self) -> usize
pub fn max_permits(&self) -> usize
Returns the maximum number of permits (initial count).
Sourcepub fn acquire<'a, 'b>(
&'a self,
cx: &'b Cx,
count: usize,
) -> AcquireFuture<'a, 'b>
pub fn acquire<'a, 'b>( &'a self, cx: &'b Cx, count: usize, ) -> AcquireFuture<'a, 'b>
Acquires the given number of permits asynchronously.
Sourcepub fn try_acquire(
&self,
count: usize,
) -> Result<SemaphorePermit<'_>, TryAcquireError>
pub fn try_acquire( &self, count: usize, ) -> Result<SemaphorePermit<'_>, TryAcquireError>
Tries to acquire the given number of permits without waiting.
Sourcepub fn add_permits(&self, count: usize)
pub fn add_permits(&self, count: usize)
Adds permits back to the semaphore.
Saturates at usize::MAX if adding would overflow.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Semaphore
impl !RefUnwindSafe for Semaphore
impl Send for Semaphore
impl Sync for Semaphore
impl Unpin for Semaphore
impl UnsafeUnpin for Semaphore
impl UnwindSafe for Semaphore
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).