Skip to main content

MailboxHub

Struct MailboxHub 

Source
pub struct MailboxHub { /* private fields */ }
Expand description

Central hub for inter-agent message passing.

Manages per-agent mailboxes and a global sequence number. The sequence number increments every time a result is posted, allowing wait_for_result to efficiently block until new data arrives.

All methods use internal Mutex — the hub is designed to be shared via Arc<MailboxHub>.

Implementations§

Source§

impl MailboxHub

Source

pub fn new() -> Self

Create a new empty mailbox hub.

Source

pub fn register(&self, agent_path: &AgentPath) -> Option<ChildMailbox>

Register a new agent mailbox.

Returns the child-side handle to be given to the spawned agent task. Returns None if the agent_path is already registered.

Source

pub fn unregister(&self, agent_path: &AgentPath) -> bool

Unregister an agent mailbox.

Posts a Closed result first (to wake any waiters), then removes the entry. Returns true if the agent was registered.

Source

pub fn send_message(&self, agent_path: &AgentPath, message: String) -> bool

Send a message to a sub-agent (no execution trigger).

The message is appended to the agent’s pending message buffer. Returns true if the message was queued, false if the agent is not registered.

Source

pub fn send_task( &self, agent_path: &AgentPath, task: String, interrupt: bool, ) -> bool

Send a task to a sub-agent (triggers execution).

Drains pending messages and packages them with the task. Returns true if the task was sent, false if the agent is not registered or the channel is full.

Source

pub fn has_pending(&self, agent_path: &AgentPath) -> bool

Check if an agent has pending (unread) messages.

Source

pub fn post_result(&self, result: MailboxResult)

Post a result from a child agent.

Increments the global sequence number, waking all wait_for_result callers.

Source

pub fn subscribe_seq(&self) -> Receiver<u64>

Get a clone of the global sequence number receiver.

Used by wait_agent to watch for changes before polling.

Source

pub fn try_recv_result(&self, agent_path: &AgentPath) -> Option<MailboxResult>

Try to receive a result for a specific agent (non-blocking).

Returns the oldest unread result for the agent, or None.

Source

pub fn try_recv_any(&self) -> Option<MailboxResult>

Try to receive any result (non-blocking).

Returns the first available result from any agent mailbox.

Source

pub fn has_results(&self, agent_path: &AgentPath) -> bool

Check if an agent has unread results.

Source

pub fn total_pending_results(&self) -> usize

Return the total number of unread results across all agents.

Source

pub fn contains(&self, agent_path: &AgentPath) -> bool

Check if an agent is registered.

Source

pub fn len(&self) -> usize

Return the number of registered agents.

Source

pub fn is_empty(&self) -> bool

Return whether there are no registered agents.

Source

pub fn agent_paths(&self) -> Vec<AgentPath>

Return all registered agent paths.

Trait Implementations§

Source§

impl Default for MailboxHub

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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.
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