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

pub struct Permit { /* fields omitted */ }
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

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

Returns true if the permit has been acquired

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

Try to acquire the permit.

Release a permit back to the semaphore

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.