Struct async_unsync::semaphore::Semaphore
source · pub struct Semaphore { /* private fields */ }Expand description
An unsynchronized (!Sync), simple semaphore for asynchronous permit
acquisition.
Implementations§
source§impl Semaphore
impl Semaphore
sourcepub const fn new(permits: usize) -> Self
pub const fn new(permits: usize) -> Self
Creates a new semaphore with the initial number of permits.
sourcepub fn close(&self) -> usize
pub fn close(&self) -> usize
Closes the semaphore and returns the number of notified pending waiters.
This prevents the semaphore from issuing new permits and notifies all pending waiters.
sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Returns the current number of available permits.
sourcepub fn outstanding_permits(&self) -> usize
pub fn outstanding_permits(&self) -> usize
Returns the current number of handed out permits.
sourcepub fn add_permits(&self, n: usize)
pub fn add_permits(&self, n: usize)
Adds n new permits to the semaphore.
sourcepub fn remove_permits(&self, n: usize)
pub fn remove_permits(&self, n: usize)
Permanently reduces the number of available permits by n.
sourcepub fn return_permits(&self, n: usize)
pub fn return_permits(&self, n: usize)
Returns n previously “forgotten” permits back to the semaphore.
This method complements Permit::forget and has no other uses.
sourcepub fn try_acquire(&self) -> Result<Permit<'_>, TryAcquireError>
pub fn try_acquire(&self) -> Result<Permit<'_>, TryAcquireError>
sourcepub fn try_acquire_many(&self, n: usize) -> Result<Permit<'_>, TryAcquireError>
pub fn try_acquire_many(&self, n: usize) -> Result<Permit<'_>, TryAcquireError>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Semaphore
impl !Send for Semaphore
impl !Sync for Semaphore
impl Unpin 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