kestrel-timer 0.3.6

High-performance async timer library based on Hierarchical Timing Wheel algorithm
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
// Periodic task tests for timing wheel
//
// 时间轮周期性任务测试

use crate::config::{BatchConfig, WheelConfig};
use crate::task::{
    CallbackWrapper, CompletionReceiver, TaskCompletion, TimerTask, TimerTaskWithCompletionNotifier,
};
use crate::wheel::Wheel;
use std::time::Duration;

#[test]
fn test_periodic_task_basic() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert periodic task with 50ms interval (插入 50毫秒间隔的周期性任务)
    let callback = CallbackWrapper::new(|| async {});
    let task = TimerTask::new_periodic(
        Duration::from_millis(50), // initial delay
        Duration::from_millis(50), // interval
        Some(callback),
        None,
    );
    let (task_with_notifier, completion_receiver) =
        TimerTaskWithCompletionNotifier::from_timer_task(task);
    let handle = wheel.allocate_handle();
    let task_id = handle.task_id();
    wheel.insert(handle, task_with_notifier);

    let mut rx = match completion_receiver {
        CompletionReceiver::Periodic(receiver) => receiver,
        _ => panic!("Expected periodic completion receiver"),
    };

    // Advance 5 ticks (50ms), task should trigger for the first time
    // 前进 5 个 tick (50毫秒),任务应该第一次触发
    for _ in 0..5 {
        wheel.advance();
    }

    // Check notification
    // 检查通知
    assert!(rx.try_recv().is_ok(), "Should receive first notification");

    // Verify task is still in the wheel (reinserted)
    // 验证任务仍在时间轮中(已重新插入)
    assert!(!wheel.is_empty(), "Periodic task should be reinserted");
    assert!(
        wheel.task_index.get(task_id.key()).is_some(),
        "Task should still be in index"
    );

    // Advance another 5 ticks (50ms), task should trigger again
    // 再前进 5 个 tick (50毫秒),任务应该再次触发
    for _ in 0..5 {
        wheel.advance();
    }

    // Check second notification
    // 检查第二次通知
    assert!(rx.try_recv().is_ok(), "Should receive second notification");
    assert!(
        !wheel.is_empty(),
        "Periodic task should still be in the wheel"
    );

    // Cancel the periodic task
    // 取消周期性任务
    assert!(
        wheel.cancel(task_id),
        "Should be able to cancel periodic task"
    );
    assert!(wheel.is_empty(), "Wheel should be empty after cancellation");
}

#[test]
fn test_periodic_task_cancel() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert periodic task (插入周期性任务)
    let callback = CallbackWrapper::new(|| async {});
    let task = TimerTask::new_periodic(
        Duration::from_millis(100),
        Duration::from_millis(100),
        Some(callback),
        None,
    );
    let (task_with_notifier, completion_receiver) =
        TimerTaskWithCompletionNotifier::from_timer_task(task);
    let handle = wheel.allocate_handle();
    let task_id = handle.task_id();
    wheel.insert(handle, task_with_notifier);

    let mut rx = match completion_receiver {
        CompletionReceiver::Periodic(receiver) => receiver,
        _ => panic!("Expected periodic completion receiver"),
    };

    // Cancel immediately (立即取消)
    assert!(wheel.cancel(task_id), "Should successfully cancel");

    // Check cancellation notification
    // 检查取消通知
    if let Ok(reason) = rx.try_recv() {
        assert_eq!(
            reason,
            TaskCompletion::Cancelled,
            "Should receive Cancelled notification"
        );
    } else {
        panic!("Should receive cancellation notification");
    }

    // Verify wheel is empty
    // 验证时间轮为空
    assert!(wheel.is_empty(), "Wheel should be empty");

    // Advance and verify no tasks expire
    // 前进并验证没有任务过期
    for _ in 0..20 {
        let expired = wheel.advance();
        assert!(
            expired.is_empty(),
            "No tasks should expire after cancellation"
        );
    }
}

#[test]
fn test_periodic_task_multiple_triggers() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert periodic task with 30ms interval (插入 30毫秒间隔的周期性任务)
    let callback = CallbackWrapper::new(|| async {});
    let task = TimerTask::new_periodic(
        Duration::from_millis(30),
        Duration::from_millis(30),
        Some(callback),
        None,
    );
    let (task_with_notifier, completion_receiver) =
        TimerTaskWithCompletionNotifier::from_timer_task(task);
    let handle = wheel.allocate_handle();
    let task_id = handle.task_id();
    wheel.insert(handle, task_with_notifier);

    let mut rx = match completion_receiver {
        CompletionReceiver::Periodic(receiver) => receiver,
        _ => panic!("Expected periodic completion receiver"),
    };

    // Advance and count triggers (前进并计数触发次数)
    let mut trigger_count = 0;
    for _ in 0..100 {
        wheel.advance();

        // Collect all notifications
        // 收集所有通知
        while let Ok(_) = rx.try_recv() {
            trigger_count += 1;
        }
    }

    // Task should trigger approximately 100ms / 30ms = 3 times
    // 任务应该触发大约 100毫秒 / 30毫秒 = 3 次
    assert!(
        trigger_count >= 3,
        "Should trigger at least 3 times, got {}",
        trigger_count
    );

    // Cancel the task
    // 取消任务
    wheel.cancel(task_id);
}

#[test]
fn test_periodic_task_cross_layer() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert periodic task with long interval (exceeds L0 range)
    // 插入长间隔的周期性任务(超过 L0 范围)
    // L0 range: 512 slots * 10ms = 5120ms
    let callback = CallbackWrapper::new(|| async {});
    let task = TimerTask::new_periodic(
        Duration::from_secs(10), // 10000ms > 5120ms
        Duration::from_secs(10),
        Some(callback),
        None,
    );
    let (task_with_notifier, completion_receiver) =
        TimerTaskWithCompletionNotifier::from_timer_task(task);
    let handle = wheel.allocate_handle();
    let task_id = handle.task_id();
    wheel.insert(handle, task_with_notifier);

    let mut rx = match completion_receiver {
        CompletionReceiver::Periodic(receiver) => receiver,
        _ => panic!("Expected periodic completion receiver"),
    };

    // Verify task is in L1 layer
    // 验证任务在 L1 层
    let location = wheel.task_index.get(task_id.key()).unwrap();
    assert_eq!(location.level, 1, "Long interval task should be in L1");

    // Advance to trigger the task (10000ms / 10ms = 1000 ticks)
    // 前进到触发任务 (10000毫秒 / 10毫秒 = 1000个tick)
    for _ in 0..1001 {
        wheel.advance();
    }

    // Check notification
    // 检查通知
    assert!(rx.try_recv().is_ok(), "Should receive notification");

    // Verify task is reinserted (should be in L1 again)
    // 验证任务已重新插入(应该再次在 L1 中)
    assert!(
        wheel.task_index.get(task_id.key()).is_some(),
        "Task should be reinserted"
    );
    let location = wheel.task_index.get(task_id.key()).unwrap();
    assert_eq!(location.level, 1, "Reinserted task should still be in L1");

    // Cancel the task
    // 取消任务
    wheel.cancel(task_id);
}

#[test]
fn test_periodic_task_batch_cancel() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert multiple periodic tasks (插入多个周期性任务)
    let mut task_ids = Vec::new();
    let mut receivers = Vec::new();

    for i in 0..5 {
        let callback = CallbackWrapper::new(|| async {});
        let task = TimerTask::new_periodic(
            Duration::from_millis(100 + i * 10),
            Duration::from_millis(100),
            Some(callback),
            None,
        );
        let (task_with_notifier, completion_receiver) =
            TimerTaskWithCompletionNotifier::from_timer_task(task);
        let handle = wheel.allocate_handle();
        let task_id = handle.task_id();
        wheel.insert(handle, task_with_notifier);
        task_ids.push(task_id);

        if let CompletionReceiver::Periodic(rx) = completion_receiver {
            receivers.push(rx);
        }
    }

    // Batch cancel all tasks (批量取消所有任务)
    let cancelled_count = wheel.cancel_batch(&task_ids);
    assert_eq!(cancelled_count, 5, "Should cancel all 5 tasks");

    // Verify all receive cancellation notifications
    // 验证所有接收到取消通知
    for mut rx in receivers {
        if let Ok(reason) = rx.try_recv() {
            assert_eq!(reason, TaskCompletion::Cancelled);
        } else {
            panic!("Should receive cancellation notification");
        }
    }

    assert!(wheel.is_empty(), "Wheel should be empty");
}

#[test]
fn test_periodic_task_with_initial_delay() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert periodic task with different initial delay and interval
    // 插入具有不同初始延迟和间隔的周期性任务
    let callback = CallbackWrapper::new(|| async {});
    let task = TimerTask::new_periodic(
        Duration::from_millis(100), // initial delay 100ms
        Duration::from_millis(50),  // interval 50ms
        Some(callback),
        None,
    );
    let (task_with_notifier, completion_receiver) =
        TimerTaskWithCompletionNotifier::from_timer_task(task);
    let handle = wheel.allocate_handle();
    let task_id = handle.task_id();
    wheel.insert(handle, task_with_notifier);

    let mut rx = match completion_receiver {
        CompletionReceiver::Periodic(receiver) => receiver,
        _ => panic!("Expected periodic completion receiver"),
    };

    // Advance 10 ticks (100ms), task should trigger for the first time
    // 前进 10 个 tick (100毫秒),任务应该第一次触发
    for _ in 0..10 {
        wheel.advance();
    }

    assert!(
        rx.try_recv().is_ok(),
        "Should receive first notification after initial delay"
    );

    // Advance another 5 ticks (50ms), task should trigger again (using interval)
    // 再前进 5 个 tick (50毫秒),任务应该再次触发(使用间隔)
    for _ in 0..5 {
        wheel.advance();
    }

    assert!(
        rx.try_recv().is_ok(),
        "Should receive second notification after interval"
    );

    // Cancel the task
    // 取消任务
    wheel.cancel(task_id);
}

#[test]
fn test_periodic_task_postpone() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert periodic task with 50ms interval
    // 插入 50毫秒间隔的周期性任务
    let callback = CallbackWrapper::new(|| async {});
    let task = TimerTask::new_periodic(
        Duration::from_millis(50),
        Duration::from_millis(50),
        Some(callback),
        None,
    );
    let (task_with_notifier, completion_receiver) =
        TimerTaskWithCompletionNotifier::from_timer_task(task);
    let handle = wheel.allocate_handle();
    let task_id = handle.task_id();
    wheel.insert(handle, task_with_notifier);

    let mut rx = match completion_receiver {
        CompletionReceiver::Periodic(receiver) => receiver,
        _ => panic!("Expected periodic completion receiver"),
    };

    // Postpone the periodic task to 100ms
    // 延期周期任务到 100毫秒
    assert!(
        wheel.postpone(task_id, Duration::from_millis(100), None),
        "Should postpone periodic task"
    );

    // Advance 5 ticks (50ms), task should not trigger yet
    // 前进 5 个 tick (50毫秒),任务还不应该触发
    for _ in 0..5 {
        wheel.advance();
    }
    assert!(
        rx.try_recv().is_err(),
        "Should not receive notification before postponed time"
    );

    // Advance another 5 ticks (total 100ms), task should trigger
    // 再前进 5 个 tick (总共 100毫秒),任务应该触发
    for _ in 0..5 {
        wheel.advance();
    }
    assert!(
        rx.try_recv().is_ok(),
        "Should receive notification at postponed time"
    );

    // Verify task is reinserted and will trigger again at interval (50ms)
    // 验证任务已重新插入,并将在间隔时间 (50毫秒) 后再次触发
    for _ in 0..5 {
        wheel.advance();
    }
    assert!(
        rx.try_recv().is_ok(),
        "Should receive second notification after interval"
    );

    wheel.cancel(task_id);
}

#[test]
fn test_periodic_task_postpone_cross_layer() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert periodic task in L0 (short interval)
    // 在 L0 层插入周期性任务(短间隔)
    let callback = CallbackWrapper::new(|| async {});
    let task = TimerTask::new_periodic(
        Duration::from_millis(100),
        Duration::from_millis(100),
        Some(callback),
        None,
    );
    let (task_with_notifier, completion_receiver) =
        TimerTaskWithCompletionNotifier::from_timer_task(task);
    let handle = wheel.allocate_handle();
    let task_id = handle.task_id();
    wheel.insert(handle, task_with_notifier);

    let mut rx = match completion_receiver {
        CompletionReceiver::Periodic(receiver) => receiver,
        _ => panic!("Expected periodic completion receiver"),
    };

    // Verify task is in L0
    // 验证任务在 L0 层
    assert_eq!(wheel.task_index.get(task_id.key()).unwrap().level, 0);

    // Postpone to long delay (should migrate to L1)
    // 延期到长延迟(应该迁移到 L1)
    // L0 range: 512 slots * 10ms = 5120ms
    assert!(wheel.postpone(task_id, Duration::from_secs(10), None));

    // Verify task migrated to L1
    // 验证任务迁移到 L1
    assert_eq!(wheel.task_index.get(task_id.key()).unwrap().level, 1);

    // Postpone back to short delay (should migrate back to L0)
    // 延期回短延迟(应该迁移回 L0)
    assert!(wheel.postpone(task_id, Duration::from_millis(200), None));

    // Verify task migrated back to L0
    // 验证任务迁移回 L0
    assert_eq!(wheel.task_index.get(task_id.key()).unwrap().level, 0);

    // Advance to trigger
    // 前进到触发
    for _ in 0..20 {
        wheel.advance();
    }
    assert!(rx.try_recv().is_ok(), "Should receive notification");

    wheel.cancel(task_id);
}

#[test]
fn test_periodic_task_batch_insert() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Create batch of periodic tasks
    // 创建批量周期性任务
    let handles = wheel.allocate_handles(10);
    let task_ids: Vec<_> = handles.iter().map(|h| h.task_id()).collect();
    let mut tasks = Vec::new();

    for i in 0..10 {
        let callback = CallbackWrapper::new(|| async {});
        let task = TimerTask::new_periodic(
            Duration::from_millis(100 + i * 10),
            Duration::from_millis(50),
            Some(callback),
            None,
        );
        let (task_with_notifier, _rx) = TimerTaskWithCompletionNotifier::from_timer_task(task);
        tasks.push(task_with_notifier);
    }

    wheel
        .insert_batch(handles, tasks)
        .expect("insert_batch should succeed");

    assert_eq!(wheel.task_index.len(), 10, "All tasks should be in index");

    // Advance and verify tasks trigger
    // 前进并验证任务触发
    for _ in 0..200 {
        let _expired = wheel.advance();
        // Some tasks should trigger during advancement
        // 某些任务应该在推进过程中触发
    }

    // All tasks should still be in wheel (periodic tasks reinsert)
    // 所有任务应该仍在时间轮中(周期性任务会重新插入)
    assert_eq!(
        wheel.task_index.len(),
        10,
        "All periodic tasks should still be in wheel"
    );

    // Batch cancel all
    // 批量取消所有
    let cancelled = wheel.cancel_batch(&task_ids);
    assert_eq!(cancelled, 10, "Should cancel all periodic tasks");
    assert!(wheel.is_empty());
}

#[test]
fn test_periodic_task_batch_postpone() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert multiple periodic tasks
    // 插入多个周期性任务
    let mut task_ids = Vec::new();
    for _ in 0..5 {
        let callback = CallbackWrapper::new(|| async {});
        let task = TimerTask::new_periodic(
            Duration::from_millis(50),
            Duration::from_millis(50),
            Some(callback),
            None,
        );
        let (task_with_notifier, _rx) = TimerTaskWithCompletionNotifier::from_timer_task(task);
        let handle = wheel.allocate_handle();
        let task_id = handle.task_id();
        wheel.insert(handle, task_with_notifier);
        task_ids.push(task_id);
    }

    // Batch postpone all tasks to 150ms
    // 批量延期所有任务到 150毫秒
    let updates: Vec<_> = task_ids
        .iter()
        .map(|&id| (id, Duration::from_millis(150)))
        .collect();
    let postponed_count = wheel.postpone_batch(updates);
    assert_eq!(postponed_count, 5, "Should postpone all 5 periodic tasks");

    // Advance 5 ticks (50ms), tasks should not trigger
    // 前进 5 个 tick (50毫秒),任务不应该触发
    for _ in 0..5 {
        let expired = wheel.advance();
        assert!(
            expired.is_empty(),
            "Tasks should not trigger before postponed time"
        );
    }

    // Advance to 15 ticks (150ms), all tasks should trigger
    // 前进到 15 个 tick (150毫秒),所有任务应该触发
    let mut total_triggered = 0;
    for _ in 0..10 {
        let expired = wheel.advance();
        total_triggered += expired.len();
    }
    assert_eq!(
        total_triggered, 5,
        "All 5 tasks should trigger at postponed time"
    );

    // Clean up
    // 清理
    wheel.cancel_batch(&task_ids);
}

#[test]
fn test_mixed_oneshot_and_periodic_tasks() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert oneshot tasks
    // 插入一次性任务
    let mut oneshot_ids = Vec::new();
    for i in 0..5 {
        let callback = CallbackWrapper::new(|| async {});
        let task = TimerTask::new_oneshot(Duration::from_millis(100 + i * 10), Some(callback));
        let (task_with_notifier, _rx) = TimerTaskWithCompletionNotifier::from_timer_task(task);
        let handle = wheel.allocate_handle();
        let task_id = handle.task_id();
        wheel.insert(handle, task_with_notifier);
        oneshot_ids.push(task_id);
    }

    // Insert periodic tasks
    // 插入周期性任务
    let mut periodic_ids = Vec::new();
    let mut periodic_receivers = Vec::new();
    for _ in 0..5 {
        let callback = CallbackWrapper::new(|| async {});
        let task = TimerTask::new_periodic(
            Duration::from_millis(100),
            Duration::from_millis(100),
            Some(callback),
            None,
        );
        let (task_with_notifier, completion_receiver) =
            TimerTaskWithCompletionNotifier::from_timer_task(task);
        let handle = wheel.allocate_handle();
        let task_id = handle.task_id();
        wheel.insert(handle, task_with_notifier);
        periodic_ids.push(task_id);

        if let CompletionReceiver::Periodic(rx) = completion_receiver {
            periodic_receivers.push(rx);
        }
    }

    assert_eq!(wheel.task_index.len(), 10, "Should have 10 tasks total");

    // Advance 15 ticks (150ms)
    // 前进 15 个 tick (150毫秒)
    let mut total_expired = 0;
    for _ in 0..15 {
        let expired = wheel.advance();
        total_expired += expired.len();
    }

    // All oneshot tasks (5) + first trigger of periodic tasks (5) = 10
    // 所有一次性任务 (5) + 周期性任务的第一次触发 (5) = 10
    assert_eq!(
        total_expired, 10,
        "Should have triggered oneshot and periodic tasks"
    );

    // Oneshot tasks should be removed, periodic tasks should remain
    // 一次性任务应该被移除,周期性任务应该保留
    assert_eq!(
        wheel.task_index.len(),
        5,
        "Only periodic tasks should remain"
    );

    // Verify all oneshot tasks are removed
    // 验证所有一次性任务已移除
    for id in &oneshot_ids {
        assert!(
            wheel.task_index.get(id.key()).is_none(),
            "Oneshot task should be removed"
        );
    }

    // Verify all periodic tasks are still present
    // 验证所有周期性任务仍然存在
    for id in &periodic_ids {
        assert!(
            wheel.task_index.get(id.key()).is_some(),
            "Periodic task should still be present"
        );
    }

    // Clean up periodic tasks
    // 清理周期性任务
    wheel.cancel_batch(&periodic_ids);
    assert!(wheel.is_empty());
}

#[test]
fn test_periodic_task_postpone_with_callback() {
    let mut wheel = Wheel::new(WheelConfig::default(), BatchConfig::default());

    // Insert periodic task
    // 插入周期性任务
    let old_callback = CallbackWrapper::new(|| async {});
    let task = TimerTask::new_periodic(
        Duration::from_millis(50),
        Duration::from_millis(50),
        Some(old_callback),
        None,
    );
    let (task_with_notifier, completion_receiver) =
        TimerTaskWithCompletionNotifier::from_timer_task(task);
    let handle = wheel.allocate_handle();
    let task_id = handle.task_id();
    wheel.insert(handle, task_with_notifier);

    let mut rx = match completion_receiver {
        CompletionReceiver::Periodic(receiver) => receiver,
        _ => panic!("Expected periodic completion receiver"),
    };

    // Postpone with new callback
    // 使用新回调延期
    let new_callback = CallbackWrapper::new(|| async {});
    assert!(wheel.postpone(task_id, Duration::from_millis(100), Some(new_callback)));

    // Advance to trigger
    // 前进到触发
    for _ in 0..10 {
        wheel.advance();
    }

    assert!(
        rx.try_recv().is_ok(),
        "Should receive notification with new callback"
    );

    wheel.cancel(task_id);
}