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()
TaskId is assigned when the task is inserted into the timing wheel.
定时器任务
用户通过两步 API 与定时器交互
- 使用
TimerTask::new_oneshot()或TimerTask::new_periodic()创建任务 - 使用
TimerWheel::register()或TimerService::register()注册任务
TaskId 在任务插入到时间轮时分配
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
Sourcepub fn new_periodic(
initial_delay: Duration,
interval: Duration,
callback: Option<CallbackWrapper>,
buffer_size: Option<NonZeroUsize>,
) -> Self
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 executioninterval: Interval between subsequent executionscallback: Callback function, optional
§Note
TaskId will be assigned when the task is inserted into the timing wheel.
创建一个新的周期性定时器任务
§参数
initial_delay: 首次执行前的初始延迟interval: 后续执行之间的间隔callback: 回调函数,可选
§注意
TaskId 将在任务插入到时间轮时分配
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