use super::*;
pub(super) async fn service_status(
mut services: tokio::sync::watch::Receiver<
BTreeMap<harmos_runtime::operations::resident::Key, harmos_runtime::operations::resident::Snapshot>,
>,
name: &str, wanted: impl Fn(&ServiceStatus) -> bool,
) -> ServiceStatus {
let key = harmos_runtime::operations::resident::Key::root(name);
let snapshot = services
.wait_for(|items| items.get(&key).and_then(|item| item.health.as_ref()).is_some_and(&wanted))
.await
.expect("the runtime keeps the status sender open");
snapshot.get(&key).and_then(|item| item.health.clone()).expect("the awaited status is present")
}