summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/utils.rs30
1 files changed, 7 insertions, 23 deletions
diff --git a/src/utils.rs b/src/utils.rs
index 5a2407a..70c8c11 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -29,28 +29,13 @@ macro_rules! try_outcome_data {
};
}
-pub trait CanBeLogged: Send + 'static {
- fn into_message(self) -> Option<String>;
- fn not_run() -> Self;
-}
-
-impl CanBeLogged for Result<(), anyhow::Error> {
- fn into_message(self) -> Option<String> {
- self.err().map(|e| e.to_string())
- }
- fn not_run() -> Self {
- Ok(())
- }
-}
-
-pub fn spawn_logged<T>(context: &'static str, future: T) -> JoinHandle<()>
+pub fn spawn_logged<F>(context: &'static str, future: F) -> JoinHandle<()>
where
- T: Future + Send + 'static,
- T::Output: CanBeLogged + Send + 'static,
+ F: Future<Output = anyhow::Result<()>> + Send + 'static,
{
tokio::spawn(async move {
- if let Some(msg) = future.await.into_message() {
- warn!("{context}: {msg}");
+ if let Err(e) = future.await {
+ warn!("{context}: {e:?}");
}
})
}
@@ -103,10 +88,9 @@ impl<'r> FromRequest<'r> for &'r DeferAction {
}
impl DeferAction {
- pub fn spawn_after_success<T>(&self, context: &'static str, future: T)
+ pub fn spawn_after_success<F>(&self, context: &'static str, future: F)
where
- T: Future + Send + 'static,
- T::Output: CanBeLogged + Send + 'static,
+ F: Future<Output = anyhow::Result<()>> + Send + 'static,
{
let mut r = self.0.subscribe();
spawn_logged(context, async move {
@@ -117,7 +101,7 @@ impl DeferAction {
r.recv().await.ok();
future.await
},
- Err(_) => CanBeLogged::not_run(),
+ Err(_) => Ok(()),
}
});
}