[−][src]Struct async_weighted_semaphore::SemaphoreGuardArc
A guard returned by Semaphore::acquire_arc
that will call Semaphore::release
when it
is dropped (falls out of scope). Can be sent between threads.
Implementations
impl SemaphoreGuardArc
[src]
pub fn new(semaphore: Arc<Semaphore>, amount: usize) -> Self
[src]
pub fn forget(self) -> usize
[src]
Drop the guard without calling Semaphore::release
. This is useful when release
s don't
correspond one-to-one with acquires
or it's difficult to send the guard to the releaser.
Examples
use async_channel::{Sender, SendError}; // Limit size of a producer-consumer queue. Receivers may wait for any number of items // to be available. async fn send<T>(semaphore: &Arc<Semaphore>, sender: &Sender<T>, message: T ) -> Result<(), SendError<T>>{ match semaphore.acquire_arc(1).await { // A semaphore can be poisoned to prevent deadlock when a channel closes. Err(PoisonError) => Err(SendError(message)), Ok(guard) => { sender.send(message).await?; guard.forget(); Ok(()) } } }
Trait Implementations
impl Debug for SemaphoreGuardArc
[src]
impl Drop for SemaphoreGuardArc
[src]
Auto Trait Implementations
impl RefUnwindSafe for SemaphoreGuardArc
impl Send for SemaphoreGuardArc
impl Sync for SemaphoreGuardArc
impl Unpin for SemaphoreGuardArc
impl UnwindSafe for SemaphoreGuardArc
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,