Module events

Module events 

Source
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§

AsyncEventBus
Async event bus using tokio broadcast channels.
Event
Event data.
EventBatch
Event batch for efficient bulk processing.
EventBus
Event bus for pub/sub communication.
EventFilter
Event filter for selective event processing.
EventReplay
Event replay system for reading persisted events.
EventStats
Event bus statistics.
EventStore
Event persistence and replay system.

Enums§

EventPayload
Event payload data.
EventType
Event types in the CHIE system.
PayloadFilter
Payload filter criteria.