pub struct WaitSet<'domain, 'participant, 'attached, A> { /* private fields */ }Expand description
An entity for blocking until one or more conditions are met.
A WaitSet collects conditions from attached entities and blocks via
wait or wait_until until at
least one of them triggers. Entities are attached with an optional typed
blob A that is returned alongside the triggered condition, allowing the
caller to identify which entity triggered the wakeup.
Pass () as A when blobs are not needed.
§Examples
use cyclonedds::{Duration, WaitSet};
let topic = Topic::<Data>::new(&participant, "MyTopic")?;
let reader = Reader::new(&topic)?;
let mut waitset = WaitSet::<()>::new(&participant)?;
waitset.attach(&reader, None)?;
waitset.wait(Duration::INFINITE)?;
let samples = reader.take()?;Implementations§
Source§impl<'d, 'p, 'a, A> WaitSet<'d, 'p, 'a, A>
impl<'d, 'p, 'a, A> WaitSet<'d, 'p, 'a, A>
Sourcepub fn new(participant: &'p Participant<'d>) -> Result<Self>
pub fn new(participant: &'p Participant<'d>) -> Result<Self>
Sourcepub fn attach(
&mut self,
entity: &'a dyn Entity,
blob: Option<&'a A>,
) -> Result<()>
pub fn attach( &mut self, entity: &'a dyn Entity, blob: Option<&'a A>, ) -> Result<()>
Attaches entity to this waitset with an optional blob.
When the entity triggers a wakeup, the associated blob is returned
by wait. If the entity is already attached, this is
a no-op.
§Errors
Returns an Error if the waitset fails to attach the
entity.
§Examples
use cyclonedds::WaitSet;
let topic = Topic::<Data>::new(&participant, "MyTopic")?;
let reader = Reader::new(&topic)?;
let mut waitset = WaitSet::<()>::new(&participant)?;
waitset.attach(&reader, None)?;Sourcepub fn detach(&mut self, entity: &'a dyn Entity) -> Result<()>
pub fn detach(&mut self, entity: &'a dyn Entity) -> Result<()>
Detaches entity from this waitset.
If the entity is not attached, this is a no-op.
§Errors
Returns an Error if the waitset fails to detach the
entity.
§Examples
use cyclonedds::WaitSet;
let topic = Topic::<Data>::new(&participant, "MyTopic")?;
let reader = Reader::new(&topic)?;
let mut waitset = WaitSet::<()>::new(&participant)?;
waitset.attach(&reader, None)?;
waitset.detach(&reader)?;Sourcepub fn set_trigger(&mut self, trigger: bool) -> Result<()>
pub fn set_trigger(&mut self, trigger: bool) -> Result<()>
Sets the trigger state of this waitset directly.
Setting to true causes any current or future wait
call to return immediately. Setting to false resets it.
§Errors
Returns an Error if the waitset fails to set the
trigger.
§Examples
use cyclonedds::WaitSet;
let mut waitset = WaitSet::<()>::new(&participant)?;
waitset.set_trigger(true)?;Sourcepub fn wait(&mut self, timeout: Duration) -> Result<Vec<&'a A>>
pub fn wait(&mut self, timeout: Duration) -> Result<Vec<&'a A>>
Blocks until at least one attached condition triggers or timeout
elapses.
Returns the blobs associated with the triggered conditions. Pass
Duration::INFINITE to block
indefinitely.
§Errors
Returns an Error if the timeout elapses without any
condition triggering or if the waitset returns an error.
§Examples
use cyclonedds::{Duration, WaitSet};
let mut waitset = WaitSet::<()>::new(&participant)?;
waitset.attach(&reader, None)?;
waitset.wait(Duration::from_secs(5))?;Sourcepub fn wait_until(&mut self, absolute_time: Time) -> Result<Vec<&'a A>>
pub fn wait_until(&mut self, absolute_time: Time) -> Result<Vec<&'a A>>
Blocks until at least one attached condition triggers or
absolute_time is reached.
Like wait but takes an absolute Time
rather than a relative timeout.
§Errors
Returns an Error if the deadline passes without any
condition triggering or if the waitset returns an error.
§Examples
use cyclonedds::{Time, WaitSet};
let mut waitset = WaitSet::<()>::new(&participant)?;
waitset.attach(&reader, None)?;
waitset.wait_until(
(std::time::SystemTime::now() + std::time::Duration::from_secs(5))
.try_into()
.unwrap(),
)?;Sourcepub fn is_attached(&self, entity: &'a dyn Entity) -> bool
pub fn is_attached(&self, entity: &'a dyn Entity) -> bool
Returns true if entity is currently attached to this waitset.
§Examples
use cyclonedds::WaitSet;
let topic = Topic::<Data>::new(&participant, "MyTopic")?;
let reader = Reader::new(&topic)?;
let mut waitset = WaitSet::<()>::new(&participant)?;
assert!(!waitset.is_attached(&reader));
waitset.attach(&reader, None)?;
assert!(waitset.is_attached(&reader));Trait Implementations§
Source§impl<A> Entity for WaitSet<'_, '_, '_, A>
impl<A> Entity for WaitSet<'_, '_, '_, A>
Source§fn instance_handle(&self) -> Result<InstanceHandle>
fn instance_handle(&self) -> Result<InstanceHandle>
InstanceHandle of this entity. Read more