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
| Name | Type | Description |
|---|---|---|
subscriptions | RwLock<HashMap<EventType | Subscriptions by event type |
global_subscriptions | RwLock<Vec<Subscription>> | Global subscriptions (receive all events) |
next_id | RwLock<usize> | Next subscription ID |
history | RwLock<Vec<Event>> | Event history (optional) |
max_history | usize | Max history size |
Methods
new
fn new() -> SelfCreate a new event bus
with_history
fn with_history(max_history: usize) -> SelfCreate with custom history size
Parameters:
| Name | Type |
|---|---|
max_history | usize |
unsubscribe
fn unsubscribe(&self, subscription_id: usize) -> boolUnsubscribe by ID
Parameters:
| Name | Type |
|---|---|
subscription_id | usize |
publish
fn publish(&self, event: Event) -> ()Publish an event
Parameters:
| Name | Type |
|---|---|
event | Event |
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:
| Name | Type |
|---|---|
event_type | EventType |
events_by_source
fn events_by_source(&self, source: &str) -> Vec<Event>Get events by source
Parameters:
| Name | Type |
|---|---|
source | &str |
clear_history
fn clear_history(&self) -> ()Clear history
subscription_count
fn subscription_count(&self, event_type: EventType) -> usizeGet subscription count for an event type
Parameters:
| Name | Type |
|---|---|
event_type | EventType |
total_subscriptions
fn total_subscriptions(&self) -> usizeGet total subscription count
Source
View on GitHubpraisonai/src/bus/mod.rs at line 201