@@ -61,17 +61,20 @@ pub trait TimerBase: Send + Sync {
61
61
62
62
/// A struct for triggering a callback at regular intervals.
63
63
///
64
- /// Calling [`spin_once `][1] or [`spin `][2] on the timer's node will wait until the configured
65
- /// period of time has passed since the timer was last called (or since it was created) before
66
- /// triggering the timer's callback.
64
+ /// If created via [`Node::create_timer() `][1], calling [`spin_once `][2] or [`spin`][3]
65
+ /// on the timer's node will wait until the configured period of time has passed since
66
+ /// the timer was last called (or since it was created) before triggering the timer's callback.
67
67
///
68
- /// The only available way to instantiate timers is via [`Node::create_timer()`][3], this
69
- /// is to ensure that [`Node`][4]s can track all the timers that have been created.
68
+ /// If created via [`Timer::new`], [`is_ready`][4] must be polled until the timer has
69
+ /// expired, after which [`execute`][5] must be called to trigger the timer's callback.
70
+ /// The timer can also be added to a [`WaitSet`][6] to block until it is ready.
70
71
///
71
- /// [1]: crate::spin_once
72
- /// [2]: crate::spin
73
- /// [3]: crate::Node::create_timer
74
- /// [4]: crate::Node
72
+ /// [1]: crate::Node::create_timer
73
+ /// [2]: crate::spin_once
74
+ /// [3]: crate::spin
75
+ /// [4]: crate::Timer::is_ready
76
+ /// [5]: crate::Timer::execute
77
+ /// [6]: crate::WaitSet
75
78
pub struct Timer {
76
79
callback : Arc < Mutex < dyn FnMut ( & mut Timer ) + Send + Sync > > ,
77
80
handle : TimerHandle ,
@@ -80,6 +83,12 @@ pub struct Timer {
80
83
impl Timer {
81
84
/// Creates a new `Timer` with the given period and callback.
82
85
/// Periods greater than i64::MAX nanoseconds will saturate to i64::MAX.
86
+ ///
87
+ /// Note that most of the time [`Node::create_timer`][1] is the better way to make
88
+ /// a new timer, as that will allow the timer to be triggered by spinning the node.
89
+ /// Timers created with [`Timer::new`] must be checked and executed by the user.
90
+ ///
91
+ /// [1]: crate::Node::create_timer
83
92
pub fn new < F > (
84
93
context : & Context ,
85
94
clock : Clock ,
0 commit comments