Skip to main content

WaitSet

Struct WaitSet 

Source
pub struct WaitSet { /* private fields */ }
Expand description

A set of conditions a thread waits on (DDS 1.4, 2.2.2.1.7): wait returns when one of them is true.

One thread at a time may wait on a WaitSet. It works with plain threads; no async runtime is needed.

use std::time::Duration;
use rustorb_dds::{GuardCondition, StatusMask, WaitSet};

let status = reader.status_condition();
status.set_enabled_statuses(StatusMask::DATA_AVAILABLE);
let stop = GuardCondition::new();
let waitset = WaitSet::new();
waitset.attach_condition(&status)?;
waitset.attach_condition(&stop)?;
loop {
    let active = waitset.wait(Duration::from_secs(10))?;
    if active.iter().any(|c| *c == stop) {
        break;
    }
    for s in reader.take() {
        println!("{:?}", s.info);
    }
}

Implementations§

Source§

impl WaitSet

Source

pub fn new() -> Self

An empty WaitSet.

Source

pub fn attach_condition(&self, condition: impl Into<Condition>) -> Result<()>

Attaches a condition (attach_condition); attaching one already attached does nothing. A thread waiting on the WaitSet checks it at once.

Source

pub fn detach_condition(&self, condition: impl Into<Condition>) -> Result<()>

Detaches a condition (detach_condition). Fails with Error::PreconditionNotMet if it is not attached.

Source

pub fn conditions(&self) -> Vec<Condition>

The conditions attached (get_conditions).

Source

pub fn wait(&self, timeout: Duration) -> Result<Vec<Condition>>

Waits until at least one attached condition is true, and returns those that are (wait). Returns at once if one is true already.

Fails with Error::Timeout if timeout passes first, and with Error::PreconditionNotMet if another thread is waiting on the WaitSet. A timeout of Duration::MAX waits for ever.

Trait Implementations§

Source§

impl Debug for WaitSet

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for WaitSet

Source§

fn default() -> Self

Returns the “default value” for a type. 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>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.