Struct tokio_sync::semaphore::Permit
source · [−]pub struct Permit { /* private fields */ }
Expand description
A semaphore permit
Tracks the lifecycle of a semaphore permit.
An instance of Permit
is intended to be used with a single instance of
Semaphore
. Using a single instance of Permit
with multiple semaphore
instances will result in unexpected behavior.
Permit
does not release the permit back to the semaphore on drop. It
is the user’s responsibility to ensure that Permit::release
is called
before dropping the permit.
Implementations
sourceimpl Permit
impl Permit
sourcepub fn new() -> Permit
pub fn new() -> Permit
Create a new Permit
.
The permit begins in the “unacquired” state.
Examples
use tokio_sync::semaphore::Permit;
let permit = Permit::new();
assert!(!permit.is_acquired());
sourcepub fn is_acquired(&self) -> bool
pub fn is_acquired(&self) -> bool
Returns true if the permit has been acquired
sourcepub fn poll_acquire(&mut self, semaphore: &Semaphore) -> Poll<(), AcquireError>
pub fn poll_acquire(&mut self, semaphore: &Semaphore) -> Poll<(), AcquireError>
Try to acquire the permit. If no permits are available, the current task is notified once a new permit becomes available.
sourcepub fn try_acquire(
&mut self,
semaphore: &Semaphore
) -> Result<(), TryAcquireError>
pub fn try_acquire(
&mut self,
semaphore: &Semaphore
) -> Result<(), TryAcquireError>
Try to acquire the permit.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Permit
impl Send for Permit
impl Sync for Permit
impl Unpin for Permit
impl !UnwindSafe for Permit
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more