pub struct InterruptibleEvent { /* private fields */ }
Expand description

A blocking object that can either be notified normally or interrupted

To block using an InterruptibleEvent, first call begin_wait. At this point, the event is in the “waiting” state, and future calls to notify or interrupt will terminate the wait.

After begin_wait returns, call block_until to block the current thread until one of the following conditions occur:

  1. The given deadline expires.
  2. At least one of the notify or interrupt functions were called after begin_wait.

It’s safe to call notify or interrupt at any time. However, calls to begin_wait and block_until must alternate, starting with begin_wait.

InterruptibleEvent uses two-phase waiting so that clients can register for notification, perform some related work, and then start blocking. This approach ensures that clients do not miss notifications that arrive after they perform the related work but before they actually start blocking.

Implementations§

source§

impl InterruptibleEvent

source

pub fn new() -> Arc<Self>

source

pub fn begin_wait<'a>(self: &'a Arc<Self>) -> EventWaitGuard<'a>

Called to initiate a wait.

Calls to notify or interrupt after this function returns will cause the event to wake up. Calls to those functions prior to calling begin_wait will be ignored.

Once called, this function cannot be called again until block_until returns. Otherwise, this function will panic.

source

pub fn notify(&self)

Wake up the event normally.

If this function is called before begin_wait, this notification is ignored. Calling this function repeatedly has no effect. If both notify and interrupt are called, the state observed by block_until is a race.

source

pub fn interrupt(&self)

Wake up the event because of an interruption.

If this function is called before begin_wait, this notification is ignored. Calling this function repeatedly has no effect. If both notify and interrupt are called, the state observed by block_until is a race.

Trait Implementations§

source§

impl Debug for InterruptibleEvent

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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>,

§

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>,

§

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<B, A> LockBefore<B> for A
where B: LockAfter<A>,

source§

impl<B, A> LockEqualOrBefore<B> for A
where A: LockBefore<B>,