Skip to main content

Receive

Trait Receive 

Source
pub trait Receive {
    // Required method
    fn recv(&mut self) -> impl Future<Output = Result<Option<Message>>> + Send;
}
Expand description

The inbound half of a link: the messages that arrive on subscribed topics.

A transport that can deliver implements this beside Transport, and anything that waits for a command, a reply, or another node’s reading takes Transport + Receive. A ladder listens on every rung that implements it and hands up whichever delivers first.

§Cancel safety

Dropping the future recv returns before it completes must not lose a message: the message stays queued for the next call. A ladder and a select! both depend on this, since they drop every future but the one that completed. Reading from a channel whose receive is itself cancel-safe, which the queue behind every transport here is, satisfies it.

§Examples

A subscriber loop that stops when the link ends:

use pamoja_core::{Message, Receive, Result};

async fn drain(link: &mut impl Receive) -> Result<Vec<Message>> {
    let mut seen = Vec::new();
    while let Some(message) = link.recv().await? {
        seen.push(message);
    }
    Ok(seen)
}

Required Methods§

Source

fn recv(&mut self) -> impl Future<Output = Result<Option<Message>>> + Send

Awaits the next message from any subscribed topic.

§Returns

Some(message) for the next message, or None once the link has ended and no further messages will arrive.

§Errors

Returns Error::Closed if the transport is not connected, or Error::Transport if the link fails while waiting.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§