22/// that prints the timer callback execution iteration. The callback is executed
33/// thanks to the spin, which is in charge of executing the timer's events among
44/// other entities' events.
5- use rclrs:: { create_node, Context , Node , Timer , RclrsError } ;
6- use std:: { env, sync:: { Arc , Mutex } } ;
5+ use rclrs:: { create_node, Context , Node , RclrsError , Timer } ;
6+ use std:: {
7+ env,
8+ sync:: { Arc , Mutex } ,
9+ } ;
710
811/// Contains both the node and timer.
912struct SimpleTimerNode {
@@ -12,7 +15,6 @@ struct SimpleTimerNode {
1215}
1316
1417impl SimpleTimerNode {
15-
1618 /// Creates a node and a timer with a callback.
1719 ///
1820 /// The callback will simply print to stdout:
@@ -26,7 +28,10 @@ impl SimpleTimerNode {
2628 context,
2729 Some ( Box :: new ( move |_| {
2830 let x = * count. lock ( ) . unwrap ( ) ;
29- println ! ( "Drinking 🧉 for the {}th time every {} nanoseconds." , x, timer_period_ns) ;
31+ println ! (
32+ "Drinking 🧉 for the {}th time every {} nanoseconds." ,
33+ x, timer_period_ns
34+ ) ;
3035 * count. lock ( ) . unwrap ( ) = x + 1 ;
3136 } ) ) ,
3237 None ,
@@ -35,10 +40,9 @@ impl SimpleTimerNode {
3540 }
3641}
3742
38-
3943fn main ( ) -> Result < ( ) , RclrsError > {
4044 let timer_period: i64 = 1e9 as i64 ; // 1 seconds.
4145 let context = Context :: new ( env:: args ( ) ) . unwrap ( ) ;
4246 let simple_timer_node = Arc :: new ( SimpleTimerNode :: new ( & context, timer_period) . unwrap ( ) ) ;
4347 rclrs:: spin ( simple_timer_node. node . clone ( ) )
44- }
48+ }
0 commit comments