Skip to content

Commit 9d68020

Browse files
committed
--wip--
1 parent c331869 commit 9d68020

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
@@ -131,6 +131,9 @@ edition = "2024"
131131
license = "GPL-3.0-only"
132132
homepage = "https://github.com/hulks/hulk"
133133

134+
[workspace.lints.rust]
135+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tokio_unstable)'] }
136+
134137
[workspace.dependencies]
135138
active_vision = { path = "crates/nodes/active_vision" }
136139
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
@@ -200,7 +200,28 @@ where
200200
F: Future<Output = Result<()>> + Send + 'static,
201201
{
202202
let span = tracing::info_span!(target: "runtime::hulk_ros_z", "hulk_ros_z_node", node);
203-
join_set.spawn(future.instrument(span));
203+
spawn_join_set_task(join_set, node, future.instrument(span));
204+
}
205+
206+
#[cfg(tokio_unstable)]
207+
fn spawn_join_set_task<F>(join_set: &mut JoinSet<Result<()>>, node: &'static str, future: F)
208+
where
209+
F: Future<Output = Result<()>> + Send + 'static,
210+
{
211+
join_set
212+
.build_task()
213+
.name(node)
214+
.spawn(future)
215+
.unwrap_or_else(|error| panic!("failed to spawn {node} task: {error}"));
216+
}
217+
218+
#[cfg(not(tokio_unstable))]
219+
fn spawn_join_set_task<F>(join_set: &mut JoinSet<Result<()>>, node: &'static str, future: F)
220+
where
221+
F: Future<Output = Result<()>> + Send + 'static,
222+
{
223+
let _ = node;
224+
join_set.spawn(future);
204225
}
205226

206227
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)