CountedEvent

Struct CountedEvent 

Source
pub struct CountedEvent<E> { /* private fields */ }
Expand description

A CountedEvent wraps a type that implements the EventSetter trait. It can tell you how many waiters there are on that very event. The count will only go up once the waiter actually starts waiting on the event. If there is an immediate return on the first time the wait is polled, the count will not go up.

The count will go up if the first call to poll wait returns Poll::Pending, indicating that the waiter is actually waiting on notification. Upon notification, the count will be decremented.

§Cancel Safety

On Drop the count is decremented if the CountedAwaiter had already incremented the count and is not yet in the complete state.

Implementations§

Source§

impl<E> CountedEvent<E>
where for<'a> E: EventSetter<'a>,

Source

pub fn new(source: E) -> Self

Source

pub fn wait(&self) -> <Self as EventSetter<'_>>::Waiter

Source

pub fn set_one(&self)

Source

pub fn set_all(&self)

Source

pub fn count(&self) -> usize

Trait Implementations§

Source§

impl<'a, E> EventSetter<'a> for CountedEvent<E>
where E: EventSetter<'a> + 'a,

Source§

type Waiter = CountedAwaiter<'a, E, <E as EventSetter<'a>>::Waiter>

The future representing a pending acquisition of the event.
Source§

fn new() -> Self

Creates a new event in the unset state. This is the expected mode of operation for most events, and means that if a task begins waiting, they will wait until the event is set.
Source§

fn new_set() -> Self

Creates an event in the set state. This means that the event can be immediately acquired.
Source§

fn wait(&'a self) -> CountedAwaiter<'a, E, E::Waiter>

Waits on the event. This returns a future which when polled will wait for the event to be acquired.
Source§

fn try_wait(&self) -> bool

Will try to immediately acquire the event along the fast path. This method is non-blocking and will return true if we could acquire the event, and false if we cannot. This will clear the set flag.
Source§

fn set_all<F: FnMut()>(&self, functor: F)

Sets the event and wakes up all events from the queue if they are pending with the functor. This functor allows more advanced book-keeping per event, for instance with counted events.
Source§

fn set_one(&self) -> bool

Sets the event. This will wake up any events from the queue if any are pending. This returns a boolean if we were able to actually wake up an event or not.
Source§

fn has_waiters(&self) -> bool

If the event has any pending waiters.

Auto Trait Implementations§

§

impl<E> !Freeze for CountedEvent<E>

§

impl<E> RefUnwindSafe for CountedEvent<E>
where E: RefUnwindSafe,

§

impl<E> Send for CountedEvent<E>
where E: Send,

§

impl<E> Sync for CountedEvent<E>
where E: Sync,

§

impl<E> Unpin for CountedEvent<E>
where E: Unpin,

§

impl<E> UnwindSafe for CountedEvent<E>
where E: UnwindSafe,

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.
Source§

impl<T> Reclaim for T