pub struct EventEngine { /* private fields */ }Expand description
事件引擎。Send + Sync:可被 Arc 共享于多线程。
Implementations§
Source§impl EventEngine
impl EventEngine
Sourcepub fn with_interval(interval: Duration) -> Self
pub fn with_interval(interval: Duration) -> Self
自定义定时间隔。
Sourcepub fn put(&self, event: Event) -> Result<(), PutError>
pub fn put(&self, event: Event) -> Result<(), PutError>
投递事件。start 前投递合法(事件入队,start 后分发,对齐原版);
已 stop / 通道断开时返回 PutError::Stopped。
Sourcepub fn register(&self, event_type: impl Into<String>, f: HandlerFn) -> HandlerId
pub fn register(&self, event_type: impl Into<String>, f: HandlerFn) -> HandlerId
注册 event_type 精确 handler,返回 HandlerId 供注销。
event_type 接受 &str / String / format!(...) 结果(对齐原版 str 语义)。
Sourcepub fn unregister(&self, id: HandlerId) -> bool
pub fn unregister(&self, id: HandlerId) -> bool
注销任意位置的 handler;true 表示确实注销了某个。
Sourcepub fn register_general(&self, f: HandlerFn) -> HandlerId
pub fn register_general(&self, f: HandlerFn) -> HandlerId
注册通用 handler(收所有事件)。
Sourcepub fn unregister_general(&self, id: HandlerId) -> bool
pub fn unregister_general(&self, id: HandlerId) -> bool
注销通用 handler。
Sourcepub fn pending_events(&self) -> u64
pub fn pending_events(&self) -> u64
已入队、尚未分发完的事件数(近似)。 使用方在 stop 前想要“等排空“,轮询此处归零即可; stop 会强制清零(残余事件按“丢弃“语义不再计数)。
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for EventEngine
impl RefUnwindSafe for EventEngine
impl Send for EventEngine
impl Sync for EventEngine
impl Unpin for EventEngine
impl UnsafeUnpin for EventEngine
impl UnwindSafe for EventEngine
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