3737
3838use parking_lot:: RwLock ;
3939use std:: collections:: { BTreeMap , VecDeque } ;
40+ use std:: future:: Future ;
4041use std:: marker:: PhantomData ;
4142use std:: sync:: Arc ;
4243use 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) ]
615646mod tests {
616647 use super :: * ;
0 commit comments