BatchHandle

Struct BatchHandle 

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

批量定时器句柄,用于管理批量调度的定时器 (Batch timer handle for managing batch-scheduled timers)

通过共享 Wheel 引用减少内存开销,同时提供批量操作和迭代器访问能力。 (Reduces memory overhead through shared Wheel reference while providing batch operations and iterator access)

注意:此类型不实现 Clone,以防止重复取消同一批定时器。如需访问单个定时器句柄,请使用 into_iter()into_handles() 进行转换。 Note: This type does not implement Clone to prevent duplicate cancellation of the same batch of timers. Use into_iter() or into_handles() to access individual timer handles.

Implementations§

Source§

impl BatchHandle

Source

pub fn cancel_all(self) -> usize

批量取消所有定时器 (Cancel all timers in batch)

§返回 (Returns)

成功取消的任务数量 (Number of successfully cancelled tasks)

§示例 (Examples)
let timer = TimerWheel::with_defaults();
let delays: Vec<Duration> = (0..10)
    .map(|_| Duration::from_secs(1))
    .collect();
let tasks = TimerWheel::create_batch(delays);
let batch = timer.register_batch(tasks);
 
let cancelled = batch.cancel_all();
println!("Canceled {} timers", cancelled);
Source

pub fn into_handles(self) -> Vec<TimerHandle>

将批量句柄转换为单个定时器句柄的 Vec (Convert batch handle to Vec of individual timer handles)

消耗 BatchHandle,为每个任务创建独立的 TimerHandle。 (Consumes BatchHandle and creates independent TimerHandle for each task)

§示例 (Examples)
let timer = TimerWheel::with_defaults();
let delays: Vec<Duration> = (0..3)
    .map(|_| Duration::from_secs(1))
    .collect();
let tasks = TimerWheel::create_batch(delays);
let batch = timer.register_batch(tasks);
 
// 转换为独立的句柄
// (Convert to individual handles)
let handles = batch.into_handles();
for handle in handles {
    // 可以单独操作每个句柄
    // (Can operate each handle individually)
}
Source

pub fn len(&self) -> usize

获取批量任务的数量 (Get the number of batch tasks)

Source

pub fn is_empty(&self) -> bool

检查批量任务是否为空 (Check if batch tasks are empty)

Source

pub fn task_ids(&self) -> &[TaskId]

获取所有任务 ID 的引用 (Get reference to all task IDs)

Source

pub fn completion_receivers( &mut self, ) -> &mut Vec<Receiver<TaskCompletionReason>>

获取所有完成通知接收器的引用 (Get reference to all completion receivers)

§返回 (Returns)

所有任务的完成通知接收器列表引用 (Reference to list of completion receivers for all tasks)

Source

pub fn into_completion_receivers(self) -> Vec<Receiver<TaskCompletionReason>>

消耗句柄,返回所有完成通知接收器 (Consume handle and return all completion receivers)

§返回 (Returns)

所有任务的完成通知接收器列表 (List of completion receivers for all tasks)

§示例 (Examples)
let timer = TimerWheel::with_defaults();
let delays: Vec<Duration> = (0..3)
    .map(|_| Duration::from_secs(1))
    .collect();
let tasks = TimerWheel::create_batch(delays);
let batch = timer.register_batch(tasks);
 
// 获取所有完成通知接收器
// (Get all completion receivers)
let receivers = batch.into_completion_receivers();
for rx in receivers {
    tokio::spawn(async move {
        if rx.await.is_ok() {
            println!("A timer completed!");
        }
    });
}

Trait Implementations§

Source§

impl IntoIterator for BatchHandle

实现 IntoIterator,允许直接迭代 BatchHandle (Implement IntoIterator to allow direct iteration over BatchHandle)

§示例 (Examples)

let timer = TimerWheel::with_defaults();
let delays: Vec<Duration> = (0..3)
    .map(|_| Duration::from_secs(1))
    .collect();
let tasks = TimerWheel::create_batch(delays);
let batch = timer.register_batch(tasks);
 
// 直接迭代,每个元素都是独立的 TimerHandle
// (Iterate directly, each element is an independent TimerHandle)
for handle in batch {
    // 可以单独操作每个句柄
    // (Can operate each handle individually)
}
Source§

type Item = TimerHandle

The type of the elements being iterated over.
Source§

type IntoIter = BatchHandleIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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.