Skip to content

Commit 52238cf

Browse files
committed
Expand on timer docs
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 9acf2ad commit 52238cf

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

rclrs/src/node.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,10 @@ impl NodeState {
912912

913913
/// Create a [`Timer`] with a repeating callback.
914914
///
915+
/// This has similar behavior to `rclcpp::Node::create_timer` by periodically
916+
/// triggering the callback of the timer. For a one-shot timer alternative,
917+
/// see [`NodeState::create_timer_oneshot`].
918+
///
915919
/// See also:
916920
/// * [`Self::create_timer_oneshot`]
917921
/// * [`Self::create_timer_inert`]
@@ -1024,14 +1028,16 @@ impl NodeState {
10241028
options: impl IntoTimerOptions<'a>,
10251029
callback: impl IntoNodeTimerRepeatingCallback<Args>,
10261030
) -> Result<Timer, RclrsError> {
1027-
self.create_timer(options, callback.into_node_timer_repeating_callback())
1031+
self.create_timer_internal(options, callback.into_node_timer_repeating_callback())
10281032
}
10291033

10301034
/// Create a [`Timer`] whose callback will be triggered once after the period
10311035
/// of the timer has elapsed. After that you will need to use
10321036
/// [`TimerState::set_repeating`] or [`TimerState::set_oneshot`] or else
10331037
/// nothing will happen the following times that the `Timer` elapses.
10341038
///
1039+
/// This does not have an equivalent in `rclcpp`.
1040+
///
10351041
/// See also:
10361042
/// * [`Self::create_timer_repeating`]
10371043
/// * [`Self::create_timer_inert`]
@@ -1058,10 +1064,10 @@ impl NodeState {
10581064
///
10591065
/// # Node Timer Oneshot Callbacks
10601066
///
1061-
/// Node Timer repeating callbacks support three signatures:
1062-
/// - <code>[FnMut] ()</code>
1063-
/// - <code>[FnMut] ([Time][2])</code>
1064-
/// - <code>[FnMut] (&[Timer])</code>
1067+
/// Node Timer OneShot callbacks support three signatures:
1068+
/// - <code>[FnOnce] ()</code>
1069+
/// - <code>[FnOnce] ([Time][2])</code>
1070+
/// - <code>[FnOnce] (&[Timer])</code>
10651071
///
10661072
/// You can choose to receive the current time when the callback is being
10671073
/// triggered.
@@ -1079,30 +1085,37 @@ impl NodeState {
10791085
options: impl IntoTimerOptions<'a>,
10801086
callback: impl IntoNodeTimerOneshotCallback<Args>,
10811087
) -> Result<Timer, RclrsError> {
1082-
self.create_timer(options, callback.into_node_timer_oneshot_callback())
1088+
self.create_timer_internal(options, callback.into_node_timer_oneshot_callback())
10831089
}
10841090

10851091
/// Create a [`Timer`] without a callback. Nothing will happen when this
10861092
/// `Timer` elapses until you use [`TimerState::set_repeating`] or
10871093
/// [`TimerState::set_oneshot`].
10881094
///
1095+
/// This function is not usually what you want. An inert timer is usually
1096+
/// just a follow-up state to a oneshot timer which is waiting to be given
1097+
/// a new callback to run. However, you could use this method to declare a
1098+
/// timer whose callbacks you will start to feed in at a later.
1099+
///
1100+
/// There is no equivalent to this function in `rclcpp`.
1101+
///
10891102
/// See also:
10901103
/// * [`Self::create_timer_repeating`]
10911104
/// * [`Self::create_timer_oneshot`]
10921105
pub fn create_timer_inert<'a>(
10931106
self: &Arc<Self>,
10941107
options: impl IntoTimerOptions<'a>,
10951108
) -> Result<Timer, RclrsError> {
1096-
self.create_timer(options, AnyTimerCallback::Inert)
1109+
self.create_timer_internal(options, AnyTimerCallback::Inert)
10971110
}
10981111

1099-
/// Used internally to create a [`Timer`].
1112+
/// Used internally to create any kind of [`Timer`].
11001113
///
11011114
/// Downstream users should instead use:
11021115
/// * [`Self::create_timer_repeating`]
11031116
/// * [`Self::create_timer_oneshot`]
11041117
/// * [`Self::create_timer_inert`]
1105-
fn create_timer<'a>(
1118+
fn create_timer_internal<'a>(
11061119
self: &Arc<Self>,
11071120
options: impl IntoTimerOptions<'a>,
11081121
callback: AnyTimerCallback<Node>,

rclrs/src/worker.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,13 @@ impl<Payload: 'static + Send + Sync> WorkerState<Payload> {
531531
/// `WorkerTimer` elapses until you use [`TimerState::set_worker_repeating`]
532532
/// or [`TimerState::set_worker_oneshot`].
533533
///
534+
/// This function is not usually what you want. An inert timer is usually
535+
/// just a follow-up state to a oneshot timer which is waiting to be given
536+
/// a new callback to run. However, you could use this method to declare a
537+
/// timer whose callbacks you will start to feed in at a later.
538+
///
539+
/// There is no equivalent to this function in `rclcpp`.
540+
///
534541
/// See also:
535542
/// * [`Self::create_timer_repeating`]
536543
/// * [`Self::create_timer_oneshot`]

0 commit comments

Comments
 (0)