Skip to main content

WaitSet

Struct WaitSet 

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

Source

pub fn new(participant: &'p Participant<'d>) -> Result<Self>

Creates a new WaitSet under a participant.

§Errors

Returns an Error if the waitset fails to create.

§Examples
use cyclonedds::WaitSet;

let mut waitset = WaitSet::<()>::new(&participant)?;
Source

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)?;
Source

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)?;
Source

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)?;
Source

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))?;
Source

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(),
)?;
Source

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> Debug for WaitSet<'_, '_, '_, A>

Source§

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

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

impl<A> Drop for WaitSet<'_, '_, '_, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<A> Entity for WaitSet<'_, '_, '_, A>

Source§

fn id(&self) -> EntityId

Returns the EntityId of this entity. Read more
Source§

fn instance_handle(&self) -> Result<InstanceHandle>

Returns the InstanceHandle of this entity. Read more
Source§

fn status_changes(&self) -> Result<Status>

Returns the set of status flags that have changed since they were last read or taken. Read more
Source§

fn take_status(&self, mask: Option<Status>) -> Result<Status>

Takes and clears the status flags matching mask, or all flags if mask is None. Read more
Source§

fn read_status(&self, mask: Option<Status>) -> Result<Status>

Reads the status flags matching mask without clearing them, or all flags if mask is None. Read more
Source§

fn status_mask(&self) -> Result<Status>

Returns the status mask enabled on the entity. Read more
Source§

fn set_status_mask(&self, mask: Status) -> Result<()>

Sets and enables a status mask on the entity. Read more

Auto Trait Implementations§

§

impl<'domain, 'participant, 'attached, A> !RefUnwindSafe for WaitSet<'domain, 'participant, 'attached, A>

§

impl<'domain, 'participant, 'attached, A> !Send for WaitSet<'domain, 'participant, 'attached, A>

§

impl<'domain, 'participant, 'attached, A> !Sync for WaitSet<'domain, 'participant, 'attached, A>

§

impl<'domain, 'participant, 'attached, A> !UnwindSafe for WaitSet<'domain, 'participant, 'attached, A>

§

impl<'domain, 'participant, 'attached, A> Freeze for WaitSet<'domain, 'participant, 'attached, A>

§

impl<'domain, 'participant, 'attached, A> Unpin for WaitSet<'domain, 'participant, 'attached, A>

§

impl<'domain, 'participant, 'attached, A> UnsafeUnpin for WaitSet<'domain, 'participant, 'attached, A>

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> Same for T

Source§

type Output = T

Should always be Self
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.