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 try_recv() to check for the reply. Implements Future for use with async executors.

Implementations§

Source§

impl<T> Promise<'_, T>

Source

pub fn try_recv(&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.

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§

impl<T> Promise<'_, T>

Source

pub async fn poll_until_ready<F, Fut>( &mut self, yield_fn: F, ) -> Result<T, NodeError>
where F: FnMut() -> Fut, Fut: Future<Output = ()>,

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

Trait Implementations§

Source§

impl<T> Future for Promise<'_, T>

Source§

type Output = Result<T, NodeError>

The type of value produced on completion.
Source§

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output>

Attempts to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations§

§

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

§

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> Unpin for Promise<'a, T>

§

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

§

impl<'a, T> !UnwindSafe 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<F> IntoFuture for F
where F: Future,

Source§

type Output = <F as Future>::Output

The output that the future will produce on completion.
Source§

type IntoFuture = F

Which kind of future are we turning this into?
Source§

fn into_future(self) -> <F as IntoFuture>::IntoFuture

Creates a future from a value. Read more
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.