Skip to main content

EventBus

Defined in the bus module.
Rust AI Agent SDK Event bus for publish-subscribe messaging.

Fields

NameTypeDescription
subscriptionsRwLock<HashMap<EventTypeSubscriptions by event type
global_subscriptionsRwLock<Vec<Subscription>>Global subscriptions (receive all events)
next_idRwLock<usize>Next subscription ID
historyRwLock<Vec<Event>>Event history (optional)
max_historyusizeMax history size

Methods

new

fn new() -> Self
Create a new event bus

with_history

fn with_history(max_history: usize) -> Self
Create with custom history size Parameters:
NameType
max_historyusize

unsubscribe

fn unsubscribe(&self, subscription_id: usize) -> bool
Unsubscribe by ID Parameters:
NameType
subscription_idusize

publish

fn publish(&self, event: Event) -> ()
Publish an event Parameters:
NameType
eventEvent

history

fn history(&self) -> Vec<Event>
Get event history

events_by_type

fn events_by_type(&self, event_type: EventType) -> Vec<Event>
Get events by type Parameters:
NameType
event_typeEventType

events_by_source

fn events_by_source(&self, source: &str) -> Vec<Event>
Get events by source Parameters:
NameType
source&str

clear_history

fn clear_history(&self) -> ()
Clear history

subscription_count

fn subscription_count(&self, event_type: EventType) -> usize
Get subscription count for an event type Parameters:
NameType
event_typeEventType

total_subscriptions

fn total_subscriptions(&self) -> usize
Get total subscription count

Source

View on GitHub

praisonai/src/bus/mod.rs at line 201