SemaphoreQueue

Struct SemaphoreQueue 

Source
pub struct SemaphoreQueue<S: SemaphoreState<Params = Params, Permit = Permit> + ?Sized, C: IsCloseable, Params = <S as SemaphoreState>::Params, Permit = <S as SemaphoreState>::Permit> { /* private fields */ }
Expand description

A queue that manages the acquisition of permits from a SemaphoreState, or queues tasks if no permits are available.

Implementations§

Source§

impl<S: SemaphoreState + ?Sized, C: IsCloseable> SemaphoreQueue<S, C>

Source

pub fn acquire<R: RawMutex>( this: &Mutex<R, Self>, params: S::Params, order: FairOrder, ) -> Acquire<'_, S, C, R>

Acquire a permit, or join the queue if not currently available.

  • If the order is FairOrder::Lifo, then we enqueue at the front of the queue.
  • If the order is FairOrder::Fifo, then we enqueue at the back of the queue.
Source

pub fn try_acquire( &mut self, params: S::Params, fairness: Fairness, ) -> Result<S::Permit, TryAcquireError<S::Params, C>>

Try acquire a permit without joining the queue.

§Errors

If there are currently not enough permits available for the given request, then TryAcquireError::NoPermits is returned.

If this is a Fairness::Fair(FairOrder::Fifo) semaphore queue, and there are other tasks waiting for permits, then TryAcquireError::NoPermits is returned.

If this semaphore is_closed, then TryAcquireError::Closed is returned.

Source§

impl<S: SemaphoreState, C: IsCloseable> SemaphoreQueue<S, C>

Source

pub fn new(state: S) -> Self

Construct a new semaphore queue, with the given SemaphoreState.

Source§

impl<S: SemaphoreState + ?Sized, C: IsCloseable> SemaphoreQueue<S, C>

Source

pub fn with_state<T>(&mut self, f: impl FnOnce(&mut S) -> T) -> T

Access the state with mutable access.

This gives direct access to the state, be careful not to break any of your own state invariants. You can use this to peek at the current state, or to modify it, eg to add or remove permits from the semaphore.

Source

pub fn is_closed(&self) -> bool

Check if the queue is closed

Source§

impl<S: SemaphoreState + ?Sized> SemaphoreQueue<S, Closeable>

Source

pub fn close(&mut self)

Close the semaphore queue.

All tasks currently waiting to acquire a token will immediately stop. No new acquire attempts will succeed.

Trait Implementations§

Source§

impl<S: SemaphoreState + Debug, C: IsCloseable> Debug for SemaphoreQueue<S, C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S, C, Params, Permit> Freeze for SemaphoreQueue<S, C, Params, Permit>
where S: Freeze + ?Sized, <C as Sealed>::Closed<()>: Freeze,

§

impl<S, C, Params = <S as SemaphoreState>::Params, Permit = <S as SemaphoreState>::Permit> !RefUnwindSafe for SemaphoreQueue<S, C, Params, Permit>

§

impl<S, C, Params, Permit> Send for SemaphoreQueue<S, C, Params, Permit>
where S: Send + ?Sized, <C as Sealed>::Closed<()>: Send, Permit: Send, <C as Sealed>::Closed<Option<Params>>: Send, Params: Send,

§

impl<S, C, Params, Permit> Sync for SemaphoreQueue<S, C, Params, Permit>
where S: Sync + ?Sized, <C as Sealed>::Closed<()>: Sync, Permit: Send, <C as Sealed>::Closed<Option<Params>>: Send, Params: Send + Sync,

§

impl<S, C, Params, Permit> Unpin for SemaphoreQueue<S, C, Params, Permit>
where S: Unpin + ?Sized, <C as Sealed>::Closed<()>: Unpin,

§

impl<S, C, Params = <S as SemaphoreState>::Params, Permit = <S as SemaphoreState>::Permit> !UnwindSafe for SemaphoreQueue<S, C, Params, Permit>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.