Skip to content

Commit 752d5ba

Browse files
committed
add default impl
1 parent 9befd31 commit 752d5ba

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ros-monitor-lib/src/lib.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ use tokio::sync::broadcast::error::RecvError;
77
pub mod types;
88
pub mod state;
99

10-
#[derive(Clone)]
10+
#[derive(Default, Clone)]
1111
pub struct RosMonitor {
1212
state: Arc<Mutex<state::RosState>>,
1313
channel: Arc<Mutex<Option<tokio::sync::broadcast::Sender<types::DiscoveryEvent>>>>,
14-
task: Arc<AbortJoinHandle>,
14+
task: Option<Arc<AbortJoinHandle>>,
1515
}
1616

1717
struct AbortJoinHandle(pub tokio::task::JoinHandle<()>);
@@ -100,6 +100,12 @@ impl RosMonitor {
100100
}.await;
101101

102102
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+
103109
let mut reason = String::new();
104110
if error.to_string().contains("error while loading shared libraries") {
105111
reason.push_str("Please make sure that ROS is sourced, and try at least ROS jazzy.");
@@ -113,12 +119,14 @@ impl RosMonitor {
113119
Self {
114120
state: state_arc,
115121
channel: channel_arc,
116-
task: Arc::new(task),
122+
task: Some(Arc::new(task)),
117123
}
118124
}
119125

120126
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 {
122130
return Err(RecvError::Closed);
123131
}
124132

0 commit comments

Comments
 (0)