BatchHandle

Struct BatchHandle 

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

Batch timer handle for managing batch-scheduled timers (without completion receivers)

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.

批量定时器句柄,用于管理批量调度的定时器(不含完成通知接收器)

注意:此类型未实现 Clone 以防止重复取消同一批定时器。使用 into_iter()into_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_with_completion = timer.register_batch(tasks);
let (rxs, batch) = batch_with_completion.into_parts();
 
let cancelled = batch.cancel_all();
println!("Canceled {} timers", cancelled);
Source

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

Convert batch handle to Vec of individual timer handles

Consumes BatchHandle and creates independent TimerHandle for each task

将批量句柄转换为单个定时器句柄的 Vec

消费 BatchHandle 并为每个任务创建独立的 TimerHandle

§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_with_completion = timer.register_batch(tasks);
let (rxs, batch) = batch_with_completion.into_parts();
 
// 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]

Get reference to all task IDs

获取所有任务 ID 的引用

Source

pub fn postpone_all(self, new_delay: Duration) -> usize

Batch postpone timers (keep original callbacks)

§Parameters
  • new_delay: New delay duration applied to all timers
§Returns

Number of successfully postponed tasks

批量推迟定时器 (保持原始回调)

§参数
  • new_delay: 应用于所有定时器的新延迟时间
§返回值

成功推迟的任务数量

§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_with_completion = timer.register_batch(tasks);
let (rxs, batch) = batch_with_completion.into_parts();
 
// Postpone all timers to 5 seconds
let postponed = batch.postpone_all(Duration::from_secs(5));
println!("Postponed {} timers", postponed);
Source

pub fn postpone_each(self, delays: Vec<Duration>) -> usize

Batch postpone timers with individual delays (keep original callbacks)

§Parameters
  • delays: List of new delay durations for each timer (must match the number of tasks)
§Returns

Number of successfully postponed tasks

批量推迟定时器,每个定时器使用不同延迟 (保持原始回调)

§参数
  • delays: 每个定时器的新延迟时间列表(必须与任务数量匹配)
§返回值

成功推迟的任务数量

§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_with_completion = timer.register_batch(tasks);
let (rxs, batch) = batch_with_completion.into_parts();
 
// Postpone each timer with different delays
let new_delays = vec![
    Duration::from_secs(2),
    Duration::from_secs(3),
    Duration::from_secs(4),
];
let postponed = batch.postpone_each(new_delays);
println!("Postponed {} timers", postponed);
Source

pub fn postpone_each_with_callbacks( self, updates: Vec<(Duration, Option<CallbackWrapper>)>, ) -> usize

Batch postpone timers with individual delays and callbacks

§Parameters
  • updates: List of tuples of (new delay, new callback) for each timer
§Returns

Number of successfully postponed tasks

批量推迟定时器,每个定时器使用不同延迟和回调

§参数
  • updates: 每个定时器的 (新延迟, 新回调) 元组列表
§返回值

成功推迟的任务数量

§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_with_completion = timer.register_batch(tasks);
let (rxs, batch) = batch_with_completion.into_parts();
 
// Postpone each timer with different delays and callbacks
let updates = vec![
    (Duration::from_secs(2), Some(CallbackWrapper::new(|| async {}))),
    (Duration::from_secs(3), None),
    (Duration::from_secs(4), Some(CallbackWrapper::new(|| async {}))),
];
let postponed = batch.postpone_each_with_callbacks(updates);
println!("Postponed {} timers", postponed);

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.