pub struct InProcessEventBus { /* private fields */ }Expand description
In-process, synchronous event bus implementation.
This is the default event bus implementation that delivers events synchronously to all registered handlers in the same process.
§Thread Safety
Uses Arc<Mutex<>> internally for thread-safe handler management.
§Performance
- Synchronous delivery means handlers block the publisher
- Handlers are called sequentially in subscription order
- For high-throughput scenarios, consider async/queue-based implementations
§Example
use arc_core::event_bus::{EventBus, EventHandler, InProcessEventBus};
use arc_core::event::Event;
use serde_json::json;
use async_trait::async_trait;
struct LogHandler;
#[async_trait]
impl EventHandler for LogHandler {
fn handles(&self) -> Vec<String> {
vec!["UserCreated".to_string()]
}
async fn handle(&self, event: &Event) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
println!("Event logged: {}", event.event_type);
Ok(())
}
}
let mut bus = InProcessEventBus::new();
bus.subscribe(Box::new(LogHandler)).await?;
let event = Event::new("User", "user-1", 1, "UserCreated", json!({}));
bus.publish(vec![event]).await?;Implementations§
Source§impl InProcessEventBus
impl InProcessEventBus
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new in-process event bus.
§Example
use arc_core::event_bus::InProcessEventBus;
let bus = InProcessEventBus::new();Sourcepub async fn handler_count(&self) -> usize
pub async fn handler_count(&self) -> usize
Get the number of registered handlers.
Useful for testing and diagnostics.
§Example
use arc_core::event_bus::InProcessEventBus;
let bus = InProcessEventBus::new();
assert_eq!(bus.handler_count().await, 0);Trait Implementations§
Source§impl Clone for InProcessEventBus
impl Clone for InProcessEventBus
Source§fn clone(&self) -> InProcessEventBus
fn clone(&self) -> InProcessEventBus
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Default for InProcessEventBus
impl Default for InProcessEventBus
Auto Trait Implementations§
impl !RefUnwindSafe for InProcessEventBus
impl !UnwindSafe for InProcessEventBus
impl Freeze for InProcessEventBus
impl Send for InProcessEventBus
impl Sync for InProcessEventBus
impl Unpin for InProcessEventBus
impl UnsafeUnpin for InProcessEventBus
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