diff --git a/src/fetchers.rs b/src/fetchers.rs index 69905c8a..e0b95063 100644 --- a/src/fetchers.rs +++ b/src/fetchers.rs @@ -64,13 +64,13 @@ impl MultiFetcher { .map(|fetcher| { ( fetcher.clone(), - AutoAbortJoinHandle(tokio::spawn(async move { fetcher.check().await })), + AutoAbortJoinHandle::new(tokio::spawn(async move { fetcher.check().await })), ) }) .collect(); - for (fetcher, mut handle) in handles { - match (&mut handle.0).await { + for (fetcher, handle) in handles { + match handle.await { Ok(Ok(true)) => return Some(fetcher), Ok(Ok(false)) => (), Ok(Err(err)) => { diff --git a/src/helpers.rs b/src/helpers.rs index 5a694381..4fbc12c7 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -246,7 +246,7 @@ impl AsyncFileWriter { let mut file = fs::File::create(path)?; let (tx, mut rx) = mpsc::channel::(100); - let handle = AutoAbortJoinHandle(task::spawn_blocking(move || { + let handle = AutoAbortJoinHandle::new(task::spawn_blocking(move || { while let Some(bytes) = rx.blocking_recv() { file.write_all(&*bytes)?; } @@ -300,7 +300,7 @@ impl AsyncFileWriter { } async fn wait(handle: &mut AutoAbortJoinHandle>) -> io::Result<()> { - match (&mut handle.0).await { + match handle.await { Ok(res) => res, Err(join_err) => Err(io::Error::new(io::ErrorKind::Other, join_err)), } @@ -308,7 +308,13 @@ impl AsyncFileWriter { } #[derive(Debug)] -pub struct AutoAbortJoinHandle(pub task::JoinHandle); +pub struct AutoAbortJoinHandle(task::JoinHandle); + +impl AutoAbortJoinHandle { + pub fn new(handle: task::JoinHandle) -> Self { + Self(handle) + } +} impl Drop for AutoAbortJoinHandle { fn drop(&mut self) {