2
2
/// that prints the timer callback execution iteration. The callback is executed
3
3
/// thanks to the spin, which is in charge of executing the timer's events among
4
4
/// 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
+ } ;
7
10
8
11
/// Contains both the node and timer.
9
12
struct SimpleTimerNode {
@@ -12,7 +15,6 @@ struct SimpleTimerNode {
12
15
}
13
16
14
17
impl SimpleTimerNode {
15
-
16
18
/// Creates a node and a timer with a callback.
17
19
///
18
20
/// The callback will simply print to stdout:
@@ -26,7 +28,10 @@ impl SimpleTimerNode {
26
28
context,
27
29
Some ( Box :: new ( move |_| {
28
30
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
+ ) ;
30
35
* count. lock ( ) . unwrap ( ) = x + 1 ;
31
36
} ) ) ,
32
37
None ,
@@ -35,10 +40,9 @@ impl SimpleTimerNode {
35
40
}
36
41
}
37
42
38
-
39
43
fn main ( ) -> Result < ( ) , RclrsError > {
40
44
let timer_period: i64 = 1e9 as i64 ; // 1 seconds.
41
45
let context = Context :: new ( env:: args ( ) ) . unwrap ( ) ;
42
46
let simple_timer_node = Arc :: new ( SimpleTimerNode :: new ( & context, timer_period) . unwrap ( ) ) ;
43
47
rclrs:: spin ( simple_timer_node. node . clone ( ) )
44
- }
48
+ }
0 commit comments