Skip to content

Commit e8f037f

Browse files
committed
use timer
Signed-off-by: Michael X. Grey <[email protected]>
1 parent 5a5d156 commit e8f037f

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

examples/worker_demo/src/main.rs

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rclrs::*;
2-
use std::sync::Arc;
2+
use std::time::Duration;
33

44
fn main() -> Result<(), RclrsError> {
55
let mut executor = Context::default_from_env()?.create_basic_executor();
@@ -15,27 +15,16 @@ fn main() -> Result<(), RclrsError> {
1515
},
1616
)?;
1717

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+
};
2624

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+
)?;
3928

4029
println!(
4130
"Beginning repeater... \n >> \

0 commit comments

Comments
 (0)