File tree Expand file tree Collapse file tree 1 file changed +10
-21
lines changed Expand file tree Collapse file tree 1 file changed +10
-21
lines changed Original file line number Diff line number Diff line change 1
1
use rclrs:: * ;
2
- use std:: sync :: Arc ;
2
+ use std:: time :: Duration ;
3
3
4
4
fn main ( ) -> Result < ( ) , RclrsError > {
5
5
let mut executor = Context :: default_from_env ( ) ?. create_basic_executor ( ) ;
@@ -15,27 +15,16 @@ fn main() -> Result<(), RclrsError> {
15
15
} ,
16
16
) ?;
17
17
18
- // // Use this timer-based implementation when timers are available instead
19
- // // of using std::thread::spawn.
20
- // let _timer = worker.create_timer_repeating(
21
- // Duration::from_secs(1),
22
- // move |data: &mut String| {
23
- // let msg = example_interfaces::msg::String {
24
- // data: data.clone()
25
- // };
18
+ let _timer = worker. create_timer_repeating (
19
+ Duration :: from_secs ( 1 ) ,
20
+ move |data : & mut String | {
21
+ let msg = example_interfaces:: msg:: String {
22
+ data : data. clone ( )
23
+ } ;
26
24
27
- // publisher.publish(msg).ok();
28
- // }
29
- // )?;
30
-
31
- std:: thread:: spawn ( move || loop {
32
- std:: thread:: sleep ( std:: time:: Duration :: from_secs ( 1 ) ) ;
33
- let publisher = Arc :: clone ( & publisher) ;
34
- let _ = worker. run ( move |data : & mut String | {
35
- let msg = example_interfaces:: msg:: String { data : data. clone ( ) } ;
36
- publisher. publish ( msg) . unwrap ( ) ;
37
- } ) ;
38
- } ) ;
25
+ publisher. publish ( msg) . ok ( ) ;
26
+ }
27
+ ) ?;
39
28
40
29
println ! (
41
30
"Beginning repeater... \n >> \
You can’t perform that action at this time.
0 commit comments