Handle JoinHandle panic in view

This commit is contained in:
blank X 2021-02-04 10:43:32 +07:00
parent 11402254e1
commit aed8a28aac
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 20 additions and 7 deletions

2
Cargo.lock generated
View File

@ -202,7 +202,7 @@ dependencies = [
[[package]]
name = "hanimers"
version = "0.1.2"
version = "0.1.3"
dependencies = [
"clap",
"quick-xml",

View File

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

View File

@ -20,14 +20,27 @@ pub async fn view(arg_m: &ArgMatches<'_>) {
let handles = arg_m.values_of("id").unwrap().map(|id| {
let cloned_client = client.clone();
let id = id.to_string();
tokio::spawn(async move {
(utils::get_hentai(cloned_client, &id).await, id)
})
let cid = id.clone();
(tokio::spawn(async move {
utils::get_hentai(cloned_client, &cid).await
}), id)
}).collect::<Vec<_>>();
let mut fail = false;
let mut one_done = false;
for handle in handles {
let (hentai, id) = handle.await.unwrap();
let (handle, id) = handle;
let hentai = match handle.await {
Ok(hentai) => hentai,
Err(err) => {
if one_done {
eprintln!("");
}
eprintln!("ID: {}\nError: {}", id, err);
fail = true;
one_done = true;
continue;
}
};
match hentai {
Ok(hentai) => {
match hentai {

View File

@ -8,7 +8,7 @@ fn main() {
let matches = App::new("hanimers")
.about("hanime.tv downloader in rust")
// let's hope i remember to bump the version xd
.version("0.1.2")
.version("0.1.3")
.setting(AppSettings::SubcommandRequiredElseHelp)
.subcommand(
SubCommand::with_name("search")