Skip to content

Commit ed5382b

Browse files
committed
* Updated documentation around creating timers
1 parent bf00394 commit ed5382b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

rclrs/src/node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ impl Node {
323323
Ok(subscription)
324324
}
325325

326-
/// Create a [`Timer`][1].
326+
/// Create a [`Timer`][1] that will use the node's clock.
327327
///
328328
/// A Timer may be modified via the `Arc` returned by this function or from
329329
/// within its callback.
330-
/// A weak pointer to the `Timer` is stored within this node.
330+
/// A weak reference counter to the `Timer` is stored within this node.
331331
///
332332
/// [1]: crate::Timer
333333
pub fn create_timer<F>(

rclrs/src/timer.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,20 @@ pub trait TimerBase: Send + Sync {
6161

6262
/// A struct for triggering a callback at regular intervals.
6363
///
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.
6767
///
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.
7071
///
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
7578
pub struct Timer {
7679
callback: Arc<Mutex<dyn FnMut(&mut Timer) + Send + Sync>>,
7780
handle: TimerHandle,
@@ -80,6 +83,12 @@ pub struct Timer {
8083
impl Timer {
8184
/// Creates a new `Timer` with the given period and callback.
8285
/// 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
8392
pub fn new<F>(
8493
context: &Context,
8594
clock: Clock,

0 commit comments

Comments
 (0)