I've found that I can basically do
use example_interfaces::msg::Bool;
use rclrs::*;
use std::time::Duration;
#[tokio::main]
async fn main() {
let mut executor = Context::default_from_env().unwrap().create_basic_executor();
let node = executor.create_node("test").unwrap();
let executor_task = tokio::task::spawn_blocking(move || executor.spin(SpinOptions::default()));
node.create_async_subscription("topic_foo", async |msg: Bool| {
println!("one");
tokio::time::sleep(Duration::from_secs(1)).await;
println!("two");
tokio::time::sleep(Duration::from_secs(1)).await;
println!("three");
});
executor_task.await.unwrap().first_error().unwrap();
}
and this works (although weirdly, using tokio::task::spawn() with executor.run_async() causes a crash). Am I going to run into issues doing this? I really like having some of tokio's tools at my disposal, and I really want to use an async fn main().
I've found that I can basically do
and this works (although weirdly, using
tokio::task::spawn()withexecutor.run_async()causes a crash). Am I going to run into issues doing this? I really like having some oftokio's tools at my disposal, and I really want to use anasync fn main().