Trait Semaphore

Source
pub trait Semaphore: Default {
    type Instant: Instant;

    // Required methods
    fn give(&self);
    fn try_take(&self) -> bool;
    fn take(&self, timeout: Option<Duration>) -> bool;

    // Provided method
    fn take_iter(&self, timeout: Option<Duration>) -> TakeIter<'_, Self>  { ... }
}
Expand description

Binary semaphore.

Required Associated Types§

Required Methods§

Source

fn give(&self)

Increment semaphore.

Does nothing if already given.

Source

fn try_take(&self) -> bool

Try decrement semaphore.

Returns previous value.

Does nothing if already taken.

Source

fn take(&self, timeout: Option<Duration>) -> bool

Wait for semaphore to be given and take it.

Returns:

  • on success - true,
  • on timeout - false.

Provided Methods§

Source

fn take_iter(&self, timeout: Option<Duration>) -> TakeIter<'_, Self>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§