pub struct TimerHandle { /* private fields */ }Expand description
Timer handle for managing timer lifecycle (without completion receiver)
Note: This type does not implement Clone to prevent duplicate cancellation of the same timer. Each timer should have only one owner.
定时器句柄,用于管理定时器生命周期(不含完成通知接收器)
注意:此类型未实现 Clone 以防止重复取消同一定时器。每个定时器应该只有一个所有者。
Implementations§
Source§impl TimerHandle
impl TimerHandle
Sourcepub fn cancel(&self) -> Result<bool, TimerError>
pub fn cancel(&self) -> Result<bool, TimerError>
Cancel the timer
§Returns
Returns true if task exists and is successfully cancelled, otherwise false
取消定时器
§返回值
如果任务存在且成功取消则返回 true,否则返回 false
§Examples (示例)
let timer = TimerWheel::with_defaults();
let callback = Some(CallbackWrapper::new(|| async {}));
let task = TimerTask::new_oneshot(Duration::from_secs(1), callback);
let allocated_handle = timer.allocate_handle();
let handle = timer.register(allocated_handle, task).unwrap();
// Cancel the timer
let success = handle.cancel().unwrap();
println!("Canceled successfully: {}", success);Sourcepub fn postpone(
&self,
new_delay: Duration,
callback: Option<CallbackWrapper>,
) -> Result<bool, TimerError>
pub fn postpone( &self, new_delay: Duration, callback: Option<CallbackWrapper>, ) -> Result<bool, TimerError>
Postpone the timer
§Parameters
new_delay: New delay duration, recalculated from current timecallback: New callback function, passNoneto keep original callback, passSometo replace with new callback
§Returns
Returns true if task exists and is successfully postponed, otherwise false
推迟定时器
§参数
new_delay: 新的延迟时间,从当前时间重新计算callback: 新的回调函数,传递None保持原始回调,传递Some替换为新的回调
§返回值
如果任务存在且成功推迟则返回 true,否则返回 false
§Examples (示例)
let timer = TimerWheel::with_defaults();
let callback = Some(CallbackWrapper::new(|| async {}));
let task = TimerTask::new_oneshot(Duration::from_secs(1), callback);
let allocated_handle = timer.allocate_handle();
let handle = timer.register(allocated_handle, task).unwrap();
// Postpone to 5 seconds
let success = handle.postpone(Duration::from_secs(5), None).unwrap();
println!("Postponed successfully: {}", success);Auto Trait Implementations§
impl !RefUnwindSafe for TimerHandle
impl !UnwindSafe for TimerHandle
impl Freeze for TimerHandle
impl Send for TimerHandle
impl Sync for TimerHandle
impl Unpin for TimerHandle
impl UnsafeUnpin for TimerHandle
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