Skip to main content

Promise

Struct Promise 

Source
pub struct Promise<'a, T> { /* private fields */ }
Expand description

A pending reply from a non-blocking service or action call.

Poll with take() to check for the reply. Implements Future for use with async executors.

Implementations§

Source§

impl<T> Promise<'_, T>

Source

pub fn take(&mut self) -> Result<Option<T>, NodeError>

Try to receive the reply (non-blocking).

Returns Ok(Some(reply)) if the reply has arrived, Ok(None) if still pending. Take one message if the middleware has one — phase-379 W3.

Named take after rcl (rcl_take) and rclcpp (Subscription::take), which spell the non-blocking receive that way — as does our own C surface. NOT after rclrs: its subscription API is callback/worker-driven and has no public polling counterpart at all (its take_* methods are private), which is why the ledger records this as an extension against the Rust reference rather than a match. take was Rust channel vocabulary that reads as a different contract to a ROS 2 user: both are non-blocking and both report emptiness without failing, so nothing asked for the other word. Renamed as a clean break, no shim.

Source

pub fn take_with_info(&mut self) -> Result<Option<(T, ServiceInfo)>, NodeError>

take, plus the reply’s ServiceInfo — issue 2136.

rclrs’s client.call::<_, (Response, ServiceInfo)>(..), and upstream rmw_take_response’s rmw_service_info_t: request_id is the request this reply answers (this client’s GID and the sequence number of its request), source_timestamp is when the SERVER sent the reply, on its clock, and received_timestamp is when this client received it. As for a service callback’s info, a field the backend cannot report is None — see nros_core::ServiceInfo for which backend fills which.

Source§

impl<T> Promise<'_, T>

Source

pub fn wait( &mut self, executor: &mut Executor<'_>, timeout: Duration, ) -> Result<T, NodeError>

Block until the reply arrives, spinning the executor.

Internally calls executor.spin_once() in a loop until the reply arrives or timeout_ms is exhausted. This is equivalent to the manual spin+poll loop pattern but more ergonomic for simple use cases.

No borrow conflict: executor and self (which borrows the standalone client) are disjoint objects.

§Errors

Returns NodeError::Timeout if the reply does not arrive within timeout_ms milliseconds.

Source

pub fn wait_with_info( &mut self, executor: &mut Executor<'_>, timeout: Duration, ) -> Result<(T, ServiceInfo), NodeError>

wait, plus the reply’s ServiceInfo — issue 2136. See take_with_info.

Auto Trait Implementations§

§

impl<'a, T> !RefUnwindSafe for Promise<'a, T>

§

impl<'a, T> !Send for Promise<'a, T>

§

impl<'a, T> !Sync for Promise<'a, T>

§

impl<'a, T> !UnwindSafe for Promise<'a, T>

§

impl<'a, T> Freeze for Promise<'a, T>

§

impl<'a, T> Unpin for Promise<'a, T>

§

impl<'a, T> UnsafeUnpin for Promise<'a, 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> 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 = 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.