use std::{
collections::{BTreeMap, BTreeSet},
sync::Mutex,
};
pub(crate) struct Health(Mutex<BTreeMap<String, bool>>);
impl Health {
pub(crate) fn new() -> Self {
Self(Mutex::new(BTreeMap::new()))
}
pub(crate) fn set(&self, name: String, healthy: bool) {
self.0
.lock()
.unwrap_or_else(|error| error.into_inner())
.insert(name, healthy);
}
pub(crate) fn names(&self) -> BTreeSet<String> {
self.0
.lock()
.unwrap_or_else(|error| error.into_inner())
.keys()
.cloned()
.collect()
}
pub(crate) fn ready(&self) -> bool {
self.0
.lock()
.unwrap_or_else(|error| error.into_inner())
.values()
.all(|healthy| *healthy)
}
}