33/// thanks to the spin, which is in charge of executing the timer's events among
44/// other entities' events.
55use rclrs:: { create_node, Context , Node , RclrsError , Timer } ;
6- use std:: {
7- env,
8- sync:: Arc ,
9- time:: Duration ,
10- } ;
6+ use std:: { env, sync:: Arc , time:: Duration } ;
117
128/// Contains both the node and timer.
139struct SimpleTimerNode {
@@ -25,22 +21,17 @@ impl SimpleTimerNode {
2521 fn new ( context : & Context , timer_period : Duration ) -> Result < Self , RclrsError > {
2622 let node = create_node ( context, "simple_timer_node" ) ?;
2723 let mut x = 0 ;
28- let timer = node. create_timer_repeating (
29- timer_period,
30- move || {
31- x += 1 ;
32- println ! (
33- "Drinking 🧉 for the {x}th time every {:?}." ,
34- timer_period,
35- ) ;
36- } ,
37- ) ?;
24+ let timer = node. create_timer_repeating ( timer_period, move || {
25+ x += 1 ;
26+ println ! ( "Drinking 🧉 for the {x}th time every {:?}." , timer_period, ) ;
27+ } ) ?;
3828 Ok ( Self { node, timer } )
3929 }
4030}
4131
4232fn main ( ) -> Result < ( ) , RclrsError > {
4333 let context = Context :: new ( env:: args ( ) ) . unwrap ( ) ;
44- let simple_timer_node = Arc :: new ( SimpleTimerNode :: new ( & context, Duration :: from_secs ( 1 ) ) . unwrap ( ) ) ;
34+ let simple_timer_node =
35+ Arc :: new ( SimpleTimerNode :: new ( & context, Duration :: from_secs ( 1 ) ) . unwrap ( ) ) ;
4536 rclrs:: spin ( simple_timer_node. node . clone ( ) )
4637}
0 commit comments