Skip to content

Commit 00f582c

Browse files
committed
--wip--
1 parent 910273f commit 00f582c

5 files changed

Lines changed: 64 additions & 3 deletions

File tree

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ edition = "2024"
133133
license = "GPL-3.0-only"
134134
homepage = "https://github.com/hulks/hulk"
135135

136+
[workspace.lints.rust]
137+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] }
138+
136139
[workspace.dependencies]
137140
active_vision = { path = "crates/nodes/active_vision" }
138141
aliveness = { path = "crates/aliveness" }

crates/hulk_ros_z/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ edition.workspace = true
55
license.workspace = true
66
homepage.workspace = true
77

8+
[lints]
9+
workspace = true
10+
811
[package.metadata.pepsi]
912
cross-compile = true
1013

crates/hulk_ros_z/src/main.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,28 @@ where
214214
F: Future<Output = Result<()>> + Send + 'static,
215215
{
216216
let span = tracing::info_span!(target: "runtime::hulk_ros_z", "hulk_ros_z_node", node);
217-
join_set.spawn(future.instrument(span));
217+
spawn_join_set_task(join_set, node, future.instrument(span));
218+
}
219+
220+
#[cfg(tokio_unstable)]
221+
fn spawn_join_set_task<F>(join_set: &mut JoinSet<Result<()>>, node: &'static str, future: F)
222+
where
223+
F: Future<Output = Result<()>> + Send + 'static,
224+
{
225+
join_set
226+
.build_task()
227+
.name(node)
228+
.spawn(future)
229+
.unwrap_or_else(|error| panic!("failed to spawn {node} task: {error}"));
230+
}
231+
232+
#[cfg(not(tokio_unstable))]
233+
fn spawn_join_set_task<F>(join_set: &mut JoinSet<Result<()>>, node: &'static str, future: F)
234+
where
235+
F: Future<Output = Result<()>> + Send + 'static,
236+
{
237+
let _ = node;
238+
join_set.spawn(future);
218239
}
219240

220241
async fn monitor(join_set: &mut JoinSet<Result<()>>) -> Result<()> {

crates/ros-z/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ homepage.workspace = true
88
[lib]
99
crate-type = ["lib"]
1010

11+
[lints]
12+
workspace = true
13+
1114
[dependencies]
1215
arc-swap = { workspace = true }
1316
byteorder = { workspace = true }

crates/ros-z/src/cache.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
3838
use parking_lot::RwLock;
3939
use std::collections::{BTreeMap, VecDeque};
40+
use std::future::Future;
4041
use std::marker::PhantomData;
4142
use std::sync::Arc;
4243
use tracing::{Instrument, debug, warn};
@@ -480,6 +481,7 @@ where
480481
let inner_cb = inner.clone();
481482
let node = sub_builder.context.node.fully_qualified_name();
482483
let topic = sub_builder.topic.clone();
484+
let task_name = cache_task_name(&node, &topic, "zenoh");
483485

484486
let raw_subscriber = sub_builder.raw().build().await?;
485487
let mut raw_subscriber_task = raw_subscriber;
@@ -490,7 +492,8 @@ where
490492
topic = %topic,
491493
stamp = "zenoh"
492494
);
493-
let task = tokio::spawn(
495+
let task = spawn_cache_task(
496+
&task_name,
494497
async move {
495498
loop {
496499
let sample = match raw_subscriber_task.recv().await {
@@ -570,6 +573,7 @@ where
570573
let inner_cb = inner.clone();
571574
let node = sub_builder.context.node.fully_qualified_name();
572575
let topic = sub_builder.topic.clone();
576+
let task_name = cache_task_name(&node, &topic, "extractor");
573577

574578
let raw_subscriber = sub_builder.raw().build().await?;
575579
let mut raw_subscriber_task = raw_subscriber;
@@ -580,7 +584,8 @@ where
580584
topic = %topic,
581585
stamp = "extractor"
582586
);
583-
let task = tokio::spawn(
587+
let task = spawn_cache_task(
588+
&task_name,
584589
async move {
585590
loop {
586591
let sample = match raw_subscriber_task.recv().await {
@@ -611,6 +616,32 @@ where
611616
}
612617
}
613618

619+
fn cache_task_name(node: &str, topic: &str, stamp: &str) -> String {
620+
format!("ros_z_cache:{node}:{topic}:{stamp}")
621+
}
622+
623+
#[cfg(tokio_unstable)]
624+
fn spawn_cache_task<F>(name: &str, future: F) -> tokio::task::JoinHandle<F::Output>
625+
where
626+
F: Future + Send + 'static,
627+
F::Output: Send + 'static,
628+
{
629+
tokio::task::Builder::new()
630+
.name(name)
631+
.spawn(future)
632+
.unwrap_or_else(|error| panic!("failed to spawn {name} task: {error}"))
633+
}
634+
635+
#[cfg(not(tokio_unstable))]
636+
fn spawn_cache_task<F>(name: &str, future: F) -> tokio::task::JoinHandle<F::Output>
637+
where
638+
F: Future + Send + 'static,
639+
F::Output: Send + 'static,
640+
{
641+
let _ = name;
642+
tokio::spawn(future)
643+
}
644+
614645
#[cfg(test)]
615646
mod tests {
616647
use super::*;

0 commit comments

Comments
 (0)