pub struct Promise<'a, T> { /* private fields */ }Expand description
A pending reply from a non-blocking service or action call.
Poll with try_recv() to check for the reply.
Implements Future for use with async executors.
Implementations§
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
try_recv() 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?;