Expand description
Timer module 定时器模块
§Overview / 概述
This module provides efficient timer management using a hierarchical timing wheel. The timing wheel provides O(1) insertion, deletion, and advancement.
本模块使用分层时间轮提供高效的定时器管理。 时间轮提供O(1)插入、删除和推进操作。
§Timer Wheel Algorithm / 时间轮算法
The timer wheel is organized as a hierarchy of wheels with different granularities:
- Wheel 0: 1ms resolution, 256 slots (256ms range)
- Wheel 1: 256ms resolution, 64 slots (16.384s range)
- Wheel 2: 16.384s resolution, 64 slots (1048.576s range)
- Wheel 3: 1048.576s resolution, 64 slots (67108.864s range)
时间轮组织为具有不同粒度的层级:
- 轮0:1ms分辨率,256个槽(256ms范围)
- 轮1:256ms分辨率,64个槽(16.384s范围)
- 轮2:16.384s分辨率,64个槽(1048.576s范围)
- 轮3:1048.576s分辨率,64个槽(67108.864s范围)
§Example / 示例
ⓘ
use hiver_runtime::time::{sleep, Duration};
async fn example() {
sleep(Duration::from_millis(100)).await;
println!("Woke up after 100ms");
}Structs§
- Duration
- Standard library duration re-export
标准库Duration重新导出
A
Durationtype to represent a span of time, typically used for system timeouts. - Instant
- Standard library instant re-export
标准库Instant重新导出
A measurement of a monotonically nondecreasing clock.
Opaque and useful only with
Duration. - Interval
- Interval stream 间隔流
- Sleep
- Sleep future that completes after the specified duration 在指定持续时间后完成的sleep future
- Sleep
Until - Sleep until future sleep until future
- Timer
Handle - Handle to a timer 定时器句柄
- Timer
Wheel - Hierarchical timing wheel for efficient timer management 用于高效定时器管理的分层时间轮
Functions§
- global_
timer - Get the global timer wheel 获取全局时间轮
- interval
- Interval timer that yields at regular intervals 以固定间隔产生的间隔定时器
- sleep
- Sleep for the specified duration 睡眠指定持续时间
- sleep_
until - Sleep until the specified instant 睡眠直到指定时刻