[][src]Struct tokio_sync::semaphore::Permit

pub struct Permit { /* fields omitted */ }

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.

Methods

impl Permit[src]

pub fn new() -> Permit[src]

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());

pub fn is_acquired(&self) -> bool[src]

Returns true if the permit has been acquired

pub fn poll_acquire(&mut self, semaphore: &Semaphore) -> Poll<(), AcquireError>[src]

Try to acquire the permit. If no permits are available, the current task is notified once a new permit becomes available.

pub fn try_acquire(
    &mut self,
    semaphore: &Semaphore
) -> Result<(), TryAcquireError>
[src]

Try to acquire the permit.

pub fn release(&mut self, semaphore: &Semaphore)[src]

Release a permit back to the semaphore

pub fn forget(&mut self)[src]

Forget the permit without releasing it back to the semaphore.

After calling forget, poll_acquire is able to acquire new permit from the sempahore.

Repeatedly calling forget without associated calls to add_permit will result in the semaphore losing all permits.

Trait Implementations

impl Debug for Permit[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.