pub struct OwnedSemaphore { /* private fields */ }Expand description
An owned semaphore is identical to a Semaphore except it can be owned by an actor and it’s permits can still be shared externally.
Implementations§
Source§impl OwnedSemaphore
impl OwnedSemaphore
Sourcepub fn new(permits: usize) -> Self
pub fn new(permits: usize) -> Self
Creates a new instance of OwnedSemaphore with the given permits count that can be used with owned permits.
This can be used to create a owned semaphore that lives in a state:
use hydra::OwnedSemaphore;
struct MyServer {
rate_limit: OwnedSemaphore,
}
impl MyServer {
pub fn new() -> Self {
Self {
rate_limit: OwnedSemaphore::new(100),
}
}
}Sourcepub async fn acquire(&self) -> SemaphorePermit<'_>
pub async fn acquire(&self) -> SemaphorePermit<'_>
Acquires one permit asynchronously waiting for one to become available.
Sourcepub async fn acquire_owned(&self) -> OwnedSemaphorePermit
pub async fn acquire_owned(&self) -> OwnedSemaphorePermit
Acquires one permit asynchronously waiting for one to become available.
Sourcepub async fn acquire_many(&self, count: u32) -> SemaphorePermit<'_>
pub async fn acquire_many(&self, count: u32) -> SemaphorePermit<'_>
Acquires many permits asynchronously waiting for them to become available.
Sourcepub async fn acquire_many_owned(&self, count: u32) -> OwnedSemaphorePermit
pub async fn acquire_many_owned(&self, count: u32) -> OwnedSemaphorePermit
Acquires many permits asynchronously waiting for them to become available.
Sourcepub fn try_acquire(&self) -> Result<SemaphorePermit<'_>, NoPermits>
pub fn try_acquire(&self) -> Result<SemaphorePermit<'_>, NoPermits>
Attempts to acquire a permit, returning an error if there are none available.
Sourcepub fn try_acquire_owned(&self) -> Result<OwnedSemaphorePermit, NoPermits>
pub fn try_acquire_owned(&self) -> Result<OwnedSemaphorePermit, NoPermits>
Attempts to acquire a permit, returning an error if there are none available.
Auto Trait Implementations§
impl Freeze for OwnedSemaphore
impl RefUnwindSafe for OwnedSemaphore
impl Send for OwnedSemaphore
impl Sync for OwnedSemaphore
impl Unpin for OwnedSemaphore
impl UnwindSafe for OwnedSemaphore
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