pub struct EventBus { /* private fields */ }Expand description
事件总线
事件驱动的核心组件,负责事件的发布和分发。
Implementations§
Source§impl EventBus
impl EventBus
Sourcepub fn new(config: EventBusConfig) -> Self
pub fn new(config: EventBusConfig) -> Self
创建新的事件总线
Sourcepub fn with_store(
config: EventBusConfig,
store: Option<Arc<dyn EventStore>>,
) -> Self
pub fn with_store( config: EventBusConfig, store: Option<Arc<dyn EventStore>>, ) -> Self
创建带事件存储的事件总线
Sourcepub fn subscribe<H: EventHandler + 'static>(
&self,
event_types: Vec<EventTypeName>,
handler: H,
) -> WaeResult<Subscription>
pub fn subscribe<H: EventHandler + 'static>( &self, event_types: Vec<EventTypeName>, handler: H, ) -> WaeResult<Subscription>
订阅事件
注册一个事件处理器,订阅指定类型的事件。
Sourcepub fn subscribe_with_filter<H: EventHandler + 'static, F: EventFilter + 'static>(
&self,
event_types: Vec<EventTypeName>,
handler: H,
filter: Option<F>,
) -> WaeResult<Subscription>
pub fn subscribe_with_filter<H: EventHandler + 'static, F: EventFilter + 'static>( &self, event_types: Vec<EventTypeName>, handler: H, filter: Option<F>, ) -> WaeResult<Subscription>
订阅事件 (带过滤器)
注册一个事件处理器,订阅指定类型的事件,并应用过滤器。
Sourcepub fn unsubscribe(&self, subscription_id: &str) -> WaeResult<bool>
pub fn unsubscribe(&self, subscription_id: &str) -> WaeResult<bool>
取消订阅
移除指定 ID 的订阅。
Sourcepub fn publish_data(&self, event_data: EventData) -> WaeResult<()>
pub fn publish_data(&self, event_data: EventData) -> WaeResult<()>
发布事件数据
发布已封装的事件数据。
Sourcepub async fn publish_async<E: Event + Serialize>(
&self,
event: &E,
) -> WaeResult<()>
pub async fn publish_async<E: Event + Serialize>( &self, event: &E, ) -> WaeResult<()>
异步发布事件
异步发布事件到事件总线。
Sourcepub async fn publish_data_async(&self, event_data: EventData) -> WaeResult<()>
pub async fn publish_data_async(&self, event_data: EventData) -> WaeResult<()>
异步发布事件数据
异步发布已封装的事件数据。
Sourcepub fn subscription_count(&self) -> usize
pub fn subscription_count(&self) -> usize
获取订阅数量
Sourcepub fn subscription_count_for_type(&self, event_type: &str) -> usize
pub fn subscription_count_for_type(&self, event_type: &str) -> usize
获取指定事件类型的订阅数量
Sourcepub async fn replay_events<H: EventHandler + 'static>(
&self,
store: &dyn EventStore,
handler: &H,
event_type: Option<&str>,
) -> WaeResult<u64>
pub async fn replay_events<H: EventHandler + 'static>( &self, store: &dyn EventStore, handler: &H, event_type: Option<&str>, ) -> WaeResult<u64>
事件回放
从事件存储中回放事件到指定处理器。
Auto Trait Implementations§
impl !Freeze for EventBus
impl !RefUnwindSafe for EventBus
impl Send for EventBus
impl Sync for EventBus
impl Unpin for EventBus
impl UnsafeUnpin for EventBus
impl !UnwindSafe for EventBus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more