Event Bus • Rust AI Agent SDK

EventBus: Event bus for publish-subscribe messaging.

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

rust
fn new() -> Self

Create a new event bus

with_history

rust
fn with_history(max_history: usize) -> Self

Create with custom history size

Parameters:

NameType
max_historyusize

unsubscribe

rust
fn unsubscribe(&self, subscription_id: usize) -> bool

Unsubscribe by ID

Parameters:

NameType
subscription_idusize

publish

rust
fn publish(&self, event: Event) -> ()

Publish an event

Parameters:

NameType
eventEvent

history

rust
fn history(&self) -> Vec<Event>

Get event history

events_by_type

rust
fn events_by_type(&self, event_type: EventType) -> Vec<Event>

Get events by type

Parameters:

NameType
event_typeEventType

events_by_source

rust
fn events_by_source(&self, source: &str) -> Vec<Event>

Get events by source

Parameters:

NameType
source&str

clear_history

rust
fn clear_history(&self) -> ()

Clear history

subscription_count

rust
fn subscription_count(&self, event_type: EventType) -> usize

Get subscription count for an event type

Parameters:

NameType
event_typeEventType

total_subscriptions

rust
fn total_subscriptions(&self) -> usize

Get total subscription count

Source

View on GitHub

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