Skip to main content

Promise

Struct Promise 

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

Result of a queued request or reply.

Requests return Promise<Message>; their wait selects the expected response type or takes the message directly. Replies return Promise<()>; their wait observes local writing and flushing, not peer receipt or processing.

Dropping a promise leaves the request or reply running with its original deadline. A timeout does not mean the peer stopped working. Completed results remain available after the session closes.

A buffered response counts toward the session’s inbound byte limit until wait() or drop. It stays encoded until wait() decodes it. Late answers and answers with no matching request are discarded. Answers whose promises were dropped are also discarded. Their payloads are never decoded.

Each promise returns its result once:

use darkbio_wire::protocol::{DeviceInfoResponse, Message, Promise};
fn take_twice(promise: Promise<Message>) {
    let _ = promise.wait::<DeviceInfoResponse>();
    let _ = promise.wait::<DeviceInfoResponse>();
}

Implementations§

Source§

impl Promise<Message>

Source

pub fn wait<T>(self) -> Result<T, Error>
where T: TryFrom<Message>, Error: From<T::Error>,

Blocks for completion, then decodes the response. The response must be accepted before the request’s original deadline. Decoding is outside that deadline. An accepted response remains available after the deadline or closure.

Taking the response removes its bytes from the inbound byte count before decoding it. Invalid protobuf returns Error::Malformed and closes its original session.

Selects the expected response type at this call, either through inference or wait::<Response>(). Message extraction checks the content variant and returns Error::UnexpectedResponse on mismatch. The Message enum can also be taken directly for application pattern matching.

Source§

impl Promise<()>

Source

pub fn wait(self) -> Result<(), Error>

Blocks for local write/flush completion under the reply’s original deadline. The peer does not send another acknowledgment for this reply.

Source§

impl<T> Promise<T>

Source

pub fn notify<E: Copy + Send + 'static>(&mut self, sender: Sender<E>, event: E)

Sends event through the unbounded channel once a terminal result is ready. Requests notify on a response or error; replies notify on local write/flush completion or error. Notification does not imply success or peer receipt. The result is published before the event, so wait() can then extract it without waiting for completion. Response decoding still happens in wait().

Registering or receiving a notification neither decodes the response nor releases its retained bytes. They remain charged until wait() or drop. Deadlines are unchanged, and registration does not service expiry.

An already-completed promise sends immediately on the registering thread, even after its session is gone. Otherwise the thread settling the operation sends the event. A disconnected notification receiver discards the event without affecting the result. Copy tokens cannot run application destructors on a protocol worker; keep any associated payload on the consumer’s side.

Dropping the promise clears an unsent notification without cancelling the operation. An event already sent can outlive its promise.

§Panics

Panics if notification was already registered on this promise.

Trait Implementations§

Source§

impl<T> Drop for Promise<T>

Source§

fn drop(&mut self)

Clears an unsent event. The protocol never drops a handed-out promise under its session lock; this path only takes the notification lock.

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

Auto Trait Implementations§

§

impl<T> !Sync for Promise<T>

§

impl<T> Freeze for Promise<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for Promise<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for Promise<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Unpin for Promise<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for Promise<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Promise<T>
where PhantomData<fn() -> T>: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more