pub struct TimerHandle { /* private fields */ }Expand description
定时任务句柄 —— 支持显式取消与滑动重置;句柄析构不会自动取消。
Implementations§
Source§impl TimerHandle
impl TimerHandle
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
是否已取消(反映调用方意图,不反映驱动侧实际状态)。
Sourcepub fn has_fired(&self) -> bool
pub fn has_fired(&self) -> bool
该 once 任务是否已触发。
触发标记在驱动执行到点动作之前置位,且 Actor 事件循环 单线程消费消息,因此“触发后首批消息先于定时消息被处理” 不可能发生 —— 该查询在 Actor 上下文内无竞态。 周期任务恒返回 false(无单次触发语义)。
Sourcepub fn reset(&self, delay: Duration)
pub fn reset(&self, delay: Duration)
滑动 deadline:从现在起重新等待 delay。对已触发/已取消的任务为 no-op。
复用既有条目:驱动内活跃条目保持 O(1),不产生已取消条目残留。 代价是每次调用向驱动投递一条重置命令(跨任务发送 + 堆插入 + 唤醒驱动)。
高频滑动(如每帧喂狗,100–1000Hz)请改用
ActorContext::watchdog:其滑动
走共享原子 deadline,零跨任务命令、零驱动唤醒。
Trait Implementations§
Source§impl Clone for TimerHandle
impl Clone for TimerHandle
Auto Trait Implementations§
impl !RefUnwindSafe for TimerHandle
impl !UnwindSafe for TimerHandle
impl Forget for TimerHandle
impl Freeze for TimerHandle
impl Move for TimerHandle
impl Send for TimerHandle
impl Sync for TimerHandle
impl Unpin for TimerHandle
impl UnsafeUnpin for TimerHandle
Blanket Implementations§
impl<T> ActorMsg for Twhere
T: Send + 'static,
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