Run QuickInstall reporting using tokio::spawn

So that it is run in concurrent or even in parallel with the
`remote_exists`.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2022-06-08 19:13:10 +10:00
parent 43d5a6bdb1
commit cf87abba16
No known key found for this signature in database
GPG key ID: 591C0B03040416D6

View file

@ -3,6 +3,7 @@ use std::sync::Arc;
use log::{debug, info};
use reqwest::Method;
use tokio::task::JoinHandle;
use url::Url;
use super::Data;
@ -31,7 +32,7 @@ impl super::Fetcher for QuickInstall {
async fn check(&self) -> Result<bool, BinstallError> {
let url = self.package_url();
self.report().await?;
self.report();
info!("Checking for package at: '{url}'");
remote_exists(Url::parse(&url)?, Method::HEAD).await
}
@ -76,13 +77,16 @@ impl QuickInstall {
)
}
pub async fn report(&self) -> Result<(), BinstallError> {
pub fn report(&self) -> JoinHandle<Result<(), BinstallError>> {
let stats_url = self.stats_url();
tokio::spawn(async move {
if cfg!(debug_assertions) {
debug!("Not sending quickinstall report in debug mode");
return Ok(());
}
let url = Url::parse(&self.stats_url())?;
let url = Url::parse(&stats_url)?;
debug!("Sending installation report to quickinstall ({url})");
reqwest::Client::builder()
@ -96,6 +100,8 @@ impl QuickInstall {
url,
err,
})?;
Ok(())
})
}
}