TimerHandle

Struct TimerHandle 

Source
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

Source

pub fn cancel(&self) -> bool

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 = TimerWheel::create_task(Duration::from_secs(1), callback);
let handle_with_completion = timer.register(task);
let (rx, handle) = handle_with_completion.into_parts();
 
// Cancel the timer
let success = handle.cancel();
println!("Canceled successfully: {}", success);
Source

pub fn postpone( &self, new_delay: Duration, callback: Option<CallbackWrapper>, ) -> bool

Postpone the timer

§Parameters
  • new_delay: New delay duration, recalculated from current time
  • callback: New callback function, pass None to keep original callback, pass Some to 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 = TimerWheel::create_task(Duration::from_secs(1), callback);
let handle_with_completion = timer.register(task);
let (rx, handle) = handle_with_completion.into_parts();
 
// Postpone to 5 seconds
let success = handle.postpone(Duration::from_secs(5), None);
println!("Postponed successfully: {}", success);

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.