Skip to main content

TimerWheel

Struct TimerWheel 

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

Hierarchical timing wheel for efficient timer management 用于高效定时器管理的分层时间轮

Uses 4 wheels with different granularities to cover a wide range of timeouts. 使用4个具有不同粒度的轮来覆盖大范围的超时。

Implementations§

Source§

impl TimerWheel

Source

pub fn new() -> Self

Create a new timer wheel 创建新的时间轮

Source

pub fn cancel_timer(&self, id: u64) -> bool

Cancel a timer by ID 通过ID取消定时器

Source

pub fn current_ticks(&self) -> u64

Get the current tick count 获取当前滴答计数

Source

pub fn advance(&self, ticks: u64) -> usize

Advance the timer wheel by the specified number of ticks 将时间轮推进指定数量的滴答

Returns the number of timers that expired during this advancement. 返回在此推进期间到期的定时器数量。

Source

pub fn insert_timer(&self, duration: Duration) -> TimerHandle

Insert a timer with the specified duration 插入具有指定持续时间的定时器

Source

pub fn insert_timer_with_waker( &self, duration: Duration, waker: Waker, ) -> TimerHandle

Insert a timer with the specified duration and associated waker 插入具有指定持续时间和关联waker的定时器

Source

pub fn next_expiration(&self) -> Option<u64>

Get the next timer expiration time in milliseconds 获取下一个定时器到期时间(毫秒)

Returns None if there are no active timers. 如果没有活动定时器则返回 None

Trait Implementations§

Source§

impl Default for TimerWheel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Send for TimerWheel

Source§

impl Sync for TimerWheel

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.