pub struct LocalMesh { /* private fields */ }Implementations§
Source§impl LocalMesh
impl LocalMesh
Sourcepub fn new(name: impl Into<String>) -> Self
pub fn new(name: impl Into<String>) -> Self
Examples found in repository?
examples/mesh_architecture.rs (line 80)
78async fn main() -> Result<()> {
79 // 1. Create the Mesh (wrapped in Arc for sharing)
80 let mesh = Arc::new(LocalMesh::new("main_mesh"));
81
82 // 2. Create Agents with reference to mesh
83 let completion = Arc::new(Notify::new());
84
85 let worker = Box::new(WorkerAgent { mesh: mesh.clone() });
86 let manager = Box::new(ManagerAgent {
87 mesh: mesh.clone(),
88 completion_notify: completion.clone(),
89 });
90
91 // 3. Register Agents
92 mesh.add_agent(worker).await?;
93 mesh.add_agent(manager).await?;
94
95 // 4. Start Mesh
96 mesh.start().await?;
97
98 // Wait for the interaction to complete
99 println!("Waiting for interaction to complete...");
100 // Timeout after 5 seconds
101 tokio::select! {
102 _ = completion.notified() => {
103 println!("Interaction completed successfully!");
104 }
105 _ = tokio::time::sleep(Duration::from_secs(5)) => {
106 println!("Timeout waiting for interaction.");
107 }
108 }
109
110 // 5. Stop Mesh
111 mesh.stop().await?;
112
113 Ok(())
114}Sourcepub fn request_queue(&self) -> Arc<RequestQueue>
pub fn request_queue(&self) -> Arc<RequestQueue>
Get the request queue (for sharing with agent wrappers)
Source§impl LocalMesh
impl LocalMesh
Sourcepub async fn broadcast(
&self,
message: Message,
exclude: Option<&str>,
) -> Result<Vec<Result<()>>>
pub async fn broadcast( &self, message: Message, exclude: Option<&str>, ) -> Result<Vec<Result<()>>>
Broadcast a message to all agents in the mesh
Sourcepub async fn submit(&self, target: &str, payload: String) -> Result<String>
pub async fn submit(&self, target: &str, payload: String) -> Result<String>
Submit a request (fire-and-forget). Returns request ID.
Sourcepub fn get_pending(&self) -> Vec<MeshRequest>
pub fn get_pending(&self) -> Vec<MeshRequest>
Get pending requests
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
Check if there are pending requests
Sourcepub fn get_results(&self) -> Vec<MeshResult>
pub fn get_results(&self) -> Vec<MeshResult>
Get available results (removes them from queue)
Sourcepub fn peek_results(&self) -> Vec<MeshResult>
pub fn peek_results(&self) -> Vec<MeshResult>
Peek at results without removing
Sourcepub async fn send_reminders(&self, older_than_secs: f64) -> Result<Vec<String>>
pub async fn send_reminders(&self, older_than_secs: f64) -> Result<Vec<String>>
Send reminders for stale requests
Sourcepub async fn wait_for(
&self,
request_id: &str,
timeout_secs: f64,
reminder_interval_secs: f64,
) -> Result<MeshResult>
pub async fn wait_for( &self, request_id: &str, timeout_secs: f64, reminder_interval_secs: f64, ) -> Result<MeshResult>
Wait for a specific result with auto-reminders
Sourcepub async fn collect_results(
&self,
reminder_interval_secs: f64,
) -> Vec<MeshResult>
pub async fn collect_results( &self, reminder_interval_secs: f64, ) -> Vec<MeshResult>
Collect all results, blocking until all pending complete
Trait Implementations§
Source§impl Mesh for LocalMesh
impl Mesh for LocalMesh
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn stop<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn add_agent<'life0, 'async_trait>(
&'life0 self,
agent: Box<dyn Agent + 'static>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn send<'life0, 'life1, 'async_trait>(
&'life0 self,
message: Message,
target: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl Freeze for LocalMesh
impl !RefUnwindSafe for LocalMesh
impl Send for LocalMesh
impl Sync for LocalMesh
impl Unpin for LocalMesh
impl !UnwindSafe for LocalMesh
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more