pub struct AsyncDispatcher { /* private fields */ }Expand description
Asynchronous event dispatcher for agent systems.
The dispatcher manages a queue of events and routes them to registered agents via a router. It runs in a background task and can be stopped gracefully.
§Examples
ⓘ
use mojentic::async_dispatcher::AsyncDispatcher;
use mojentic::router::Router;
let router = Arc::new(Router::new());
let mut dispatcher = AsyncDispatcher::new(router);
dispatcher.start().await.unwrap();
dispatcher.dispatch(my_event);
dispatcher.wait_for_empty_queue(Some(Duration::from_secs(10))).await.unwrap();
dispatcher.stop().await.unwrap();Implementations§
Source§impl AsyncDispatcher
impl AsyncDispatcher
Sourcepub fn with_batch_size(self, size: usize) -> Self
pub fn with_batch_size(self, size: usize) -> Self
Sourcepub async fn start(&mut self) -> Result<()>
pub async fn start(&mut self) -> Result<()>
Start the event dispatch task.
This spawns a background task that processes events from the queue.
Sourcepub async fn stop(&mut self) -> Result<()>
pub async fn stop(&mut self) -> Result<()>
Stop the event dispatch task.
This signals the background task to stop and waits for it to complete.
Sourcepub fn dispatch(&self, event: Box<dyn Event>)
pub fn dispatch(&self, event: Box<dyn Event>)
Dispatch an event to the queue.
The event will be processed asynchronously by the background task.
§Arguments
event- The event to dispatch
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AsyncDispatcher
impl !RefUnwindSafe for AsyncDispatcher
impl Send for AsyncDispatcher
impl Sync for AsyncDispatcher
impl Unpin for AsyncDispatcher
impl !UnwindSafe for AsyncDispatcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more