summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpennae <github@quasiparticle.net>2022-07-14 07:15:54 +0200
committerpennae <github@quasiparticle.net>2022-07-14 07:15:54 +0200
commit566d6ccee21fc52943cf1862222f2e9a8927403c (patch)
tree50731ec8d0fb45e41921fedfc114a37b9b436bac
parent3986c4f2c75f0e05f7e99a87526777eaa8a53a6a (diff)
downloadminor-skulk-566d6ccee21fc52943cf1862222f2e9a8927403c.tar.gz
minor-skulk-566d6ccee21fc52943cf1862222f2e9a8927403c.tar.xz
minor-skulk-566d6ccee21fc52943cf1862222f2e9a8927403c.zip
simplify spawn_logged
-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(()),
}
});
}