Skip to main content

Module event

Module event 

Source
Expand description

Event system for pub/sub communication

This module provides an event bus that allows components to communicate without direct coupling. The event bus uses broadcast channels to allow multiple subscribers to receive the same events.

§Architecture

Publishers                    EventBus                  Subscribers
┌─────────┐                  ┌────────┐                ┌─────────────┐
│  Agent  │──publish()──────▶│        │───recv()──────▶│ SSE Handler │
└─────────┘                  │        │                └─────────────┘
                             │        │                ┌─────────────┐
┌─────────┐                  │        │───recv()──────▶│   Logger    │
│ Session │──publish()──────▶│        │                └─────────────┘
└─────────┘                  └────────┘                ┌─────────────┐
                                                       │   WebSocket │
                             subscribe() ─────────────▶└─────────────┘

§Usage

use codive_core::event::{Event, EventBus};

#[tokio::main]
async fn main() {
    let bus = EventBus::new();

    // Subscribe to events
    let mut rx = bus.subscribe();

    // Publish an event
    bus.publish(Event::SessionCreated {
        session_id: "sess_123".into(),
    });

    // Receive the event
    if let Ok(event) = rx.recv().await {
        println!("Received: {:?}", event);
    }
}

Structs§

EventBus
A pub/sub event bus for broadcasting events to multiple subscribers

Enums§

Event
Events that can occur in the agent system