TimerTask

Struct TimerTask 

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

Timer Task

Users interact via a two-step API

  1. Create task using TimerTask::new_oneshot() or TimerTask::new_periodic()
  2. Register task using TimerWheel::register() or TimerService::register()

TaskId is assigned when the task is inserted into the timing wheel.

定时器任务

用户通过两步 API 与定时器交互

  1. 使用 TimerTask::new_oneshot()TimerTask::new_periodic() 创建任务
  2. 使用 TimerWheel::register()TimerService::register() 注册任务

TaskId 在任务插入到时间轮时分配

Implementations§

Source§

impl TimerTask

Source

pub fn new_oneshot(delay: Duration, callback: Option<CallbackWrapper>) -> Self

Create a new one-shot timer task

§Parameters
  • delay: Delay duration before task execution
  • callback: Callback function, optional
§Note

TaskId will be assigned when the task is inserted into the timing wheel.

创建一个新的一次性定时器任务

§参数
  • delay: 任务执行前的延迟时间
  • callback: 回调函数,可选
§注意

TaskId 将在任务插入到时间轮时分配

Source

pub fn new_periodic( initial_delay: Duration, interval: Duration, callback: Option<CallbackWrapper>, buffer_size: Option<NonZeroUsize>, ) -> Self

Create a new periodic timer task

§Parameters
  • initial_delay: Initial delay before first execution
  • interval: Interval between subsequent executions
  • callback: Callback function, optional
§Note

TaskId will be assigned when the task is inserted into the timing wheel.

创建一个新的周期性定时器任务

§参数
  • initial_delay: 首次执行前的初始延迟
  • interval: 后续执行之间的间隔
  • callback: 回调函数,可选
§注意

TaskId 将在任务插入到时间轮时分配

Source

pub fn get_task_type(&self) -> &TaskType

Get task type

获取任务类型

Source

pub fn get_interval(&self) -> Option<Duration>

Get the interval for periodic tasks

Returns None for one-shot tasks

获取周期任务的间隔时间

对于一次性任务返回 None

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.