Expand description
Event bus for internal pub/sub communication.
This module provides a lightweight event system for decoupled communication between different parts of the CHIE node. It supports both sync and async event buses, event filtering, and event batching.
§Features
- Sync Event Bus: Standard multi-producer, multi-consumer channels
- Async Event Bus: Tokio broadcast channels for async/await code
- Event Filtering: Filter events by type, timestamp, or payload
- Event Batching: Efficient bulk event processing
- Statistics: Track event counts and subscriber metrics
§Example (Sync)
use chie_core::events::{EventBus, Event, EventType};
let bus = EventBus::new();
// Subscribe to content events
let rx = bus.subscribe(EventType::ContentAdded);
// Publish an event
bus.publish(Event::content_added("QmExample123", 1024 * 1024));
// Receive events (non-blocking)
if let Ok(event) = rx.try_recv() {
println!("Received: {:?}", event);
}§Example (Async)
use chie_core::events::{AsyncEventBus, Event, EventType};
let bus = AsyncEventBus::new(100);
let mut rx = bus.subscribe(EventType::ContentAdded);
// Publish an event
let _ = bus.publish(Event::content_added("QmExample123", 1024 * 1024));
// Receive events (async)
if let Ok(event) = rx.recv().await {
println!("Received: {:?}", event);
}§Example (Filtering)
use chie_core::events::{EventFilter, Event, EventType, PayloadFilter};
let filter = EventFilter::new()
.with_types(vec![EventType::ContentAdded])
.with_payload_filter(PayloadFilter::MinBytes(1024 * 1024));
let event = Event::content_added("QmExample123", 2 * 1024 * 1024);
assert!(filter.matches(&event));Structs§
- Async
Event Bus - Async event bus using tokio broadcast channels.
- Event
- Event data.
- Event
Batch - Event batch for efficient bulk processing.
- Event
Bus - Event bus for pub/sub communication.
- Event
Filter - Event filter for selective event processing.
- Event
Replay - Event replay system for reading persisted events.
- Event
Stats - Event bus statistics.
- Event
Store - Event persistence and replay system.
Enums§
- Event
Payload - Event payload data.
- Event
Type - Event types in the CHIE system.
- Payload
Filter - Payload filter criteria.