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
.