diff --git a/src/fetchers.rs b/src/fetchers.rs index 2e7b6d02..69905c8a 100644 --- a/src/fetchers.rs +++ b/src/fetchers.rs @@ -4,9 +4,8 @@ use std::sync::Arc; pub use gh_crate_meta::*; pub use log::debug; pub use quickinstall::*; -use tokio::task::JoinHandle; -use crate::{BinstallError, PkgFmt, PkgMeta}; +use crate::{AutoAbortJoinHandle, BinstallError, PkgFmt, PkgMeta}; mod gh_crate_meta; mod quickinstall; @@ -62,10 +61,12 @@ impl MultiFetcher { .fetchers .iter() .cloned() - .map(|fetcher| ( - fetcher.clone(), - AutoAbortJoinHandle(tokio::spawn(async move { fetcher.check().await })), - )) + .map(|fetcher| { + ( + fetcher.clone(), + AutoAbortJoinHandle(tokio::spawn(async move { fetcher.check().await })), + ) + }) .collect(); for (fetcher, mut handle) in handles { @@ -92,12 +93,3 @@ impl MultiFetcher { None } } - -#[derive(Debug)] -struct AutoAbortJoinHandle(JoinHandle<Result<bool, BinstallError>>); - -impl Drop for AutoAbortJoinHandle { - fn drop(&mut self) { - self.0.abort(); - } -} diff --git a/src/helpers.rs b/src/helpers.rs index ae7a432d..869bfedc 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -300,3 +300,12 @@ impl AsyncFileWriter { } } } + +#[derive(Debug)] +pub struct AutoAbortJoinHandle<T>(pub task::JoinHandle<T>); + +impl<T> Drop for AutoAbortJoinHandle<T> { + fn drop(&mut self) { + self.0.abort(); + } +}