Summon download workers only if data is already in the vector

This commit is contained in:
blank X 2021-01-10 00:05:01 +07:00
parent c781c62261
commit 9eb433c815
3 changed files with 11 additions and 7 deletions

2
Cargo.lock generated
View File

@ -330,7 +330,7 @@ dependencies = [
[[package]]
name = "mangafetchi"
version = "0.1.2"
version = "0.1.3"
dependencies = [
"quick-xml",
"reqwest",

View File

@ -1,6 +1,6 @@
[package]
name = "mangafetchi"
version = "0.1.2"
version = "0.1.3"
authors = ["blank X <theblankx@protonmail.com>"]
edition = "2018"

View File

@ -65,14 +65,18 @@ pub async fn run(mut args: env::Args) {
}
if !to_extend.is_empty() {
cloned_mutex.lock().await.extend(to_extend);
}
if handles.is_none() {
handles = Some(summon_handles(client.clone(), cloned_mutex).await);
}
}
}
if handles.is_some() {
for handle in handles.unwrap() {
handle.await.unwrap();
}
} else {
eprintln!("Everything has already been downloaded");
}
}
async fn summon_handles(client: reqwest::Client, mutex: Arc<Mutex<Vec<(String, PathBuf, String)>>>) -> Vec<JoinHandle<()>> {