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
impl WaitSet
Sourcepub fn attach_condition(&self, condition: impl Into<Condition>) -> Result<()>
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.
Sourcepub fn detach_condition(&self, condition: impl Into<Condition>) -> Result<()>
pub fn detach_condition(&self, condition: impl Into<Condition>) -> Result<()>
Detaches a condition (detach_condition). Fails with
Error::PreconditionNotMet if it is not attached.
Sourcepub fn conditions(&self) -> Vec<Condition>
pub fn conditions(&self) -> Vec<Condition>
The conditions attached (get_conditions).
Sourcepub fn wait(&self, timeout: Duration) -> Result<Vec<Condition>>
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.