Trait embassy_sync::semaphore::Semaphore
source · pub trait Semaphore: Sized {
type Error;
// Required methods
async fn acquire(
&self,
permits: usize,
) -> Result<SemaphoreReleaser<'_, Self>, Self::Error>;
fn try_acquire(&self, permits: usize) -> Option<SemaphoreReleaser<'_, Self>>;
async fn acquire_all(
&self,
min: usize,
) -> Result<SemaphoreReleaser<'_, Self>, Self::Error>;
fn try_acquire_all(&self, min: usize) -> Option<SemaphoreReleaser<'_, Self>>;
fn release(&self, permits: usize);
fn set(&self, permits: usize);
}
Expand description
An asynchronous semaphore.
A semaphore tracks a number of permits, typically representing a pool of shared resources. Users can acquire permits to synchronize access to those resources. The semaphore does not contain the resources themselves, only the count of available permits.
Required Associated Types§
Required Methods§
sourceasync fn acquire(
&self,
permits: usize,
) -> Result<SemaphoreReleaser<'_, Self>, Self::Error>
async fn acquire( &self, permits: usize, ) -> Result<SemaphoreReleaser<'_, Self>, Self::Error>
Asynchronously acquire one or more permits from the semaphore.
sourcefn try_acquire(&self, permits: usize) -> Option<SemaphoreReleaser<'_, Self>>
fn try_acquire(&self, permits: usize) -> Option<SemaphoreReleaser<'_, Self>>
Try to immediately acquire one or more permits from the semaphore.
sourceasync fn acquire_all(
&self,
min: usize,
) -> Result<SemaphoreReleaser<'_, Self>, Self::Error>
async fn acquire_all( &self, min: usize, ) -> Result<SemaphoreReleaser<'_, Self>, Self::Error>
Asynchronously acquire all permits controlled by the semaphore.
This method will wait until at least min
permits are available, then acquire all available permits
from the semaphore. Note that other tasks may have already acquired some permits which could be released
back to the semaphore at any time. The number of permits actually acquired may be determined by calling
SemaphoreReleaser::permits
.
sourcefn try_acquire_all(&self, min: usize) -> Option<SemaphoreReleaser<'_, Self>>
fn try_acquire_all(&self, min: usize) -> Option<SemaphoreReleaser<'_, Self>>
Try to immediately acquire all available permits from the semaphore, if at least min
permits are available.