use std::fmt::Display;
pub fn heartbeat<R: AsRef<str>, E: Display, F: Send + Future<Output = Result<R, E>> + 'static>(
kind: impl Into<String> + Send + 'static,
name: impl Into<String> + Send + 'static,
fut: F,
) {
tokio::spawn(async move {
let kind = kind.into();
let name = name.into();
match fut.await {
Ok(msg) => {
let msg = msg.as_ref();
if !msg.is_empty() {
tracing::info!("{kind} {name} {msg}");
}
}
Err(e) => {
tracing::error!("{kind} {name} {e}")
}
}
});
}