pub struct Promise<'a, T> { /* private fields */ }Expand description
Implementations§
Source§impl<T> Promise<'_, T>
impl<T> Promise<'_, T>
Sourcepub fn take(&mut self) -> Result<Option<T>, NodeError>
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§impl<T> Promise<'_, T>
impl<T> Promise<'_, T>
Sourcepub fn wait(
&mut self,
executor: &mut Executor<'_>,
timeout: Duration,
) -> Result<T, NodeError>
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§impl<T> Promise<'_, T>
impl<T> Promise<'_, T>
Sourcepub async fn poll_until_ready<F, Fut>(
&mut self,
yield_fn: F,
) -> Result<T, NodeError>
pub async fn poll_until_ready<F, Fut>( &mut self, yield_fn: F, ) -> Result<T, NodeError>
Async poll-until-ready helper for environments where the
backend’s register_waker path can’t deliver a wake.
The plain .await (via the Future impl above) parks the
caller until the backend’s listener fires the stored Waker.
That works on std builds where the backend has a
background-thread pool actively polling its listener tasks,
but it deadlocks on the nostd-runtime DDS path (and any
other cooperative backend whose listener future only runs
when something actively drives the runtime). The 160.B.1
trace pinned this to DDS’s nostd runtime: listener
futures only advance inside runtime.block_on(...), and the
parked .await consumer never issues such a call.
poll_until_ready(yield_fn) instead actively polls
take() on each turn and awaits the caller-supplied
yield future between attempts. The yield gives the executor
a chance to run other ready tasks (typically a spin_task
that drives the backend runtime via executor.spin_once()),
which in turn pumps the listener future. On the std path
this devolves to a fast poll-then-yield loop with no
correctness penalty; on nostd-runtime it’s the only shape
that completes.
§Example
let reply = client
.call(&req)?
.poll_until_ready(|| embassy_time::Timer::after_millis(5))
.await?;