Skip to main content

ArcTokioMonitor

Struct ArcTokioMonitor 

Source
pub struct ArcTokioMonitor<T> { /* private fields */ }
Expand description

Cloneable handle around a TokioMonitor.

Implementations§

Source§

impl<T> ArcTokioMonitor<T>

Source

pub fn new(state: T) -> Self

Creates an Arc-wrapped Tokio monitor.

§Arguments
  • state - Initial protected state.
§Returns

A cloneable Tokio monitor handle.

Source

pub async fn async_read<R, F>(&self, f: F) -> R
where F: FnOnce(&T) -> R,

Reads protected state asynchronously.

Source

pub async fn async_write<R, F>(&self, f: F) -> R
where F: FnOnce(&mut T) -> R,

Mutates protected state asynchronously without notifying.

Source

pub async fn async_write_notify_one<R, F>(&self, f: F) -> R
where F: FnOnce(&mut T) -> R,

Mutates protected state asynchronously and wakes one waiter.

Source

pub async fn async_write_notify_all<R, F>(&self, f: F) -> R
where F: FnOnce(&mut T) -> R,

Mutates protected state asynchronously and wakes all waiters.

Source

pub fn notify_one(&self)

Wakes one async waiter.

Source

pub fn notify_all(&self)

Wakes all async waiters.

Methods from Deref<Target = TokioMonitor<T>>§

Source

pub async fn async_read<R, F>(&self, f: F) -> R
where F: FnOnce(&T) -> R,

Acquires the monitor and reads the protected state.

§Arguments
  • f - Closure that receives an immutable reference to the state.
§Returns

The value returned by the closure.

Source

pub async fn async_write<R, F>(&self, f: F) -> R
where F: FnOnce(&mut T) -> R,

Acquires the monitor and mutates the protected state.

This does not notify waiters automatically.

§Arguments
  • f - Closure that receives a mutable reference to the state.
§Returns

The value returned by the closure.

Source

pub async fn async_write_notify_one<R, F>(&self, f: F) -> R
where F: FnOnce(&mut T) -> R,

Mutates the protected state and wakes one waiter.

§Arguments
  • f - Closure that receives a mutable reference to the state.
§Returns

The value returned by the closure.

Source

pub async fn async_write_notify_all<R, F>(&self, f: F) -> R
where F: FnOnce(&mut T) -> R,

Mutates the protected state and wakes all waiters.

§Arguments
  • f - Closure that receives a mutable reference to the state.
§Returns

The value returned by the closure.

Source

pub fn notify_one(&self)

Wakes one async waiter.

Source

pub fn notify_all(&self)

Wakes all async waiters.

Trait Implementations§

Source§

impl<T> AsRef<TokioMonitor<T>> for ArcTokioMonitor<T>

Source§

fn as_ref(&self) -> &TokioMonitor<T>

Returns a reference to the wrapped Tokio monitor.

Source§

impl<T: Send> AsyncConditionWaiter for ArcTokioMonitor<T>

Source§

fn async_wait_until<'a, R, P, F>( &'a self, predicate: P, action: F, ) -> AsyncMonitorFuture<'a, R>
where R: Send + 'a, P: FnMut(&Self::State) -> bool + Send + 'a, F: FnOnce(&mut Self::State) -> R + Send + 'a,

Returns a future that waits until the predicate becomes true.

Source§

fn async_wait_while<'a, R, P, F>( &'a self, predicate: P, action: F, ) -> AsyncMonitorFuture<'a, R>
where R: Send + 'a, P: FnMut(&Self::State) -> bool + Send + 'a, F: FnOnce(&mut Self::State) -> R + Send + 'a,

Returns a future that waits while the predicate remains true.

Source§

type State = T

State protected by the monitor.
Source§

impl<T: Send> AsyncNotificationWaiter for ArcTokioMonitor<T>

Source§

fn async_wait<'a>(&'a self) -> AsyncMonitorFuture<'a, ()>

Returns a future that resolves after an async notification.

Source§

impl<T: Send> AsyncTimeoutConditionWaiter for ArcTokioMonitor<T>

Source§

fn async_wait_until_for<'a, R, P, F>( &'a self, timeout: Duration, predicate: P, action: F, ) -> AsyncMonitorFuture<'a, WaitTimeoutResult<R>>
where R: Send + 'a, P: FnMut(&Self::State) -> bool + Send + 'a, F: FnOnce(&mut Self::State) -> R + Send + 'a,

Returns a future that waits until the predicate becomes true or times out.

Source§

fn async_wait_while_for<'a, R, P, F>( &'a self, timeout: Duration, predicate: P, action: F, ) -> AsyncMonitorFuture<'a, WaitTimeoutResult<R>>
where R: Send + 'a, P: FnMut(&Self::State) -> bool + Send + 'a, F: FnOnce(&mut Self::State) -> R + Send + 'a,

Returns a future that waits while the predicate remains true or times out.

Source§

impl<T: Send> AsyncTimeoutNotificationWaiter for ArcTokioMonitor<T>

Source§

fn async_wait_for<'a>( &'a self, timeout: Duration, ) -> AsyncMonitorFuture<'a, WaitTimeoutStatus>

Returns a future that resolves after notification or timeout.

Source§

impl<T> Clone for ArcTokioMonitor<T>

Source§

fn clone(&self) -> Self

Clones this shared Tokio monitor handle.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Default> Default for ArcTokioMonitor<T>

Source§

fn default() -> Self

Creates an Arc-wrapped Tokio monitor containing T::default().

Source§

impl<T> Deref for ArcTokioMonitor<T>

Source§

fn deref(&self) -> &Self::Target

Dereferences to the wrapped Tokio monitor.

Source§

type Target = TokioMonitor<T>

The resulting type after dereferencing.
Source§

impl<T> From<T> for ArcTokioMonitor<T>

Source§

fn from(value: T) -> Self

Creates an Arc-wrapped Tokio monitor from an initial state value.

Source§

impl<T> Notifier for ArcTokioMonitor<T>

Source§

fn notify_one(&self)

Wakes one async waiter.

Source§

fn notify_all(&self)

Wakes all async waiters.

Auto Trait Implementations§

§

impl<T> Freeze for ArcTokioMonitor<T>

§

impl<T> !RefUnwindSafe for ArcTokioMonitor<T>

§

impl<T> Send for ArcTokioMonitor<T>
where T: Send,

§

impl<T> Sync for ArcTokioMonitor<T>
where T: Send,

§

impl<T> Unpin for ArcTokioMonitor<T>

§

impl<T> UnsafeUnpin for ArcTokioMonitor<T>

§

impl<T> !UnwindSafe for ArcTokioMonitor<T>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> AsyncMonitor for T

Source§

impl<T> SharedAsyncMonitor for T
where T: AsyncMonitor + Clone + Send + Sync + 'static,