pub struct TimerTask { /* private fields */ }Expand description
Timer Task
Users interact via a two-step API
- Create task using
TimerTask::new_oneshot()orTimerTask::new_periodic() - Register task using
TimerWheel::register()orTimerService::register()
定时器任务
用户通过两步 API 与定时器交互
- 使用
TimerTask::new_oneshot()或TimerTask::new_periodic()创建任务 - 使用
TimerWheel::register()或TimerService::register()注册任务
Implementations§
Source§impl TimerTask
impl TimerTask
Sourcepub fn new_oneshot(delay: Duration, callback: Option<CallbackWrapper>) -> Self
pub fn new_oneshot(delay: Duration, callback: Option<CallbackWrapper>) -> Self
Create a new one-shot timer task
§Parameters
delay: Delay duration before task executioncallback: Callback function, optional
§Note
This is an internal method, users should use TimerWheel::create_task() or TimerService::create_task() to create tasks.
创建一个新的一次性定时器任务
§参数
delay: 任务执行前的延迟时间callback: 回调函数,可选
Sourcepub fn new_periodic(
initial_delay: Duration,
interval: Duration,
callback: Option<CallbackWrapper>,
buffer_size: Option<NonZeroU16>,
) -> Self
pub fn new_periodic( initial_delay: Duration, interval: Duration, callback: Option<CallbackWrapper>, buffer_size: Option<NonZeroU16>, ) -> Self
Create a new periodic timer task
§Parameters
initial_delay: Initial delay before first executioninterval: Interval between subsequent executionscallback: Callback function, optional
§Note
This is an internal method, users should use TimerWheel::create_periodic_task() or TimerService::create_periodic_task() to create tasks.
创建一个新的周期性定时器任务
§参数
initial_delay: 首次执行前的初始延迟interval: 后续执行之间的间隔callback: 回调函数,可选
Sourcepub fn get_id(&self) -> TaskId
pub fn get_id(&self) -> TaskId
Get task ID
获取任务 ID
§Examples (示例)
use kestrel_timer::TimerTask;
use std::time::Duration;
let task = TimerTask::new_oneshot(Duration::from_secs(1), None);
let task_id = task.get_id();
println!("Task ID: {:?}", task_id);Sourcepub fn get_task_type(&self) -> &TaskType
pub fn get_task_type(&self) -> &TaskType
Get task type
获取任务类型
Sourcepub fn get_interval(&self) -> Option<Duration>
pub fn get_interval(&self) -> Option<Duration>
Get the interval for periodic tasks
Returns None for one-shot tasks
获取周期任务的间隔时间
对于一次性任务返回 None
Auto Trait Implementations§
impl Freeze for TimerTask
impl !RefUnwindSafe for TimerTask
impl Send for TimerTask
impl Sync for TimerTask
impl Unpin for TimerTask
impl !UnwindSafe for TimerTask
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