Skip to main content

EventEngine

Struct EventEngine 

Source
pub struct EventEngine { /* private fields */ }
Expand description

事件引擎。Send + Sync:可被 Arc 共享于多线程。

Implementations§

Source§

impl EventEngine

Source

pub fn new() -> Self

新引擎,默认定时间隔 1s(对齐原版 interval: int = 1)。

Source

pub fn with_interval(interval: Duration) -> Self

自定义定时间隔。

Source

pub fn start(&self)

启动分发线程与定时线程;已启动 / 已 stop 时为空操作(幂等)。 可从任意线程调用。

Source

pub fn put(&self, event: Event) -> Result<(), PutError>

投递事件。start 前投递合法(事件入队,start 后分发,对齐原版); 已 stop / 通道断开时返回 PutError::Stopped。

Source

pub fn register(&self, event_type: impl Into<String>, f: HandlerFn) -> HandlerId

注册 event_type 精确 handler,返回 HandlerId 供注销。 event_type 接受 &str / String / format!(...) 结果(对齐原版 str 语义)。

Source

pub fn unregister(&self, id: HandlerId) -> bool

注销任意位置的 handler;true 表示确实注销了某个。

Source

pub fn register_general(&self, f: HandlerFn) -> HandlerId

注册通用 handler(收所有事件)。

Source

pub fn unregister_general(&self, id: HandlerId) -> bool

注销通用 handler。

Source

pub fn is_active(&self) -> bool

引擎是否在运行。

Source

pub fn pending_events(&self) -> u64

已入队、尚未分发完的事件数(近似)。 使用方在 stop 前想要“等排空“,轮询此处归零即可; stop 会强制清零(残余事件按“丢弃“语义不再计数)。

Source

pub fn stop(&self)

停止引擎并 join 两线程;幂等,可从任意线程调用。 队列残余事件被丢弃(对齐原版);stop 后引擎不可重启。

Trait Implementations§

Source§

impl Default for EventEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.