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 waiters(&self) -> usize
pub fn waiters(&self) -> usize
Returns the number of currently registered [Future
]s waiting for a
Permit
.
Sourcepub fn available_permits(&self) -> usize
pub fn available_permits(&self) -> usize
Returns the current number of available 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
.