@@ -7,11 +7,11 @@ use tokio::sync::broadcast::error::RecvError;
7
7
pub mod types;
8
8
pub mod state;
9
9
10
- #[ derive( Clone ) ]
10
+ #[ derive( Default , Clone ) ]
11
11
pub struct RosMonitor {
12
12
state : Arc < Mutex < state:: RosState > > ,
13
13
channel : Arc < Mutex < Option < tokio:: sync:: broadcast:: Sender < types:: DiscoveryEvent > > > > ,
14
- task : Arc < AbortJoinHandle > ,
14
+ task : Option < Arc < AbortJoinHandle > > ,
15
15
}
16
16
17
17
struct AbortJoinHandle ( pub tokio:: task:: JoinHandle < ( ) > ) ;
@@ -100,6 +100,12 @@ impl RosMonitor {
100
100
} . await ;
101
101
102
102
if let Err ( error) = error {
103
+ if let RosMonitorError :: SpawnError ( err) = & error {
104
+ if err. kind ( ) == std:: io:: ErrorKind :: NotFound {
105
+ log:: warn!( "ROS discovery is not available on this platform" ) ;
106
+ }
107
+ }
108
+
103
109
let mut reason = String :: new ( ) ;
104
110
if error. to_string ( ) . contains ( "error while loading shared libraries" ) {
105
111
reason. push_str ( "Please make sure that ROS is sourced, and try at least ROS jazzy." ) ;
@@ -113,12 +119,14 @@ impl RosMonitor {
113
119
Self {
114
120
state : state_arc,
115
121
channel : channel_arc,
116
- task : Arc :: new ( task) ,
122
+ task : Some ( Arc :: new ( task) ) ,
117
123
}
118
124
}
119
125
120
126
pub fn subscribe ( & self ) -> Result < impl futures:: TryStream < Item = Result < types:: DiscoveryEvent , RecvError > > , RecvError > {
121
- if self . task . 0 . is_finished ( ) {
127
+ let is_finished = self . task . as_ref ( ) . map ( |task| task. 0 . is_finished ( ) ) . unwrap_or ( true ) ;
128
+
129
+ if is_finished {
122
130
return Err ( RecvError :: Closed ) ;
123
131
}
124
132
0 commit comments