From 8c6f8afbb7ce2793ae407090eb1265821fbb28dd Mon Sep 17 00:00:00 2001 From: hatoo Date: Fri, 10 Jan 2025 21:45:56 +0900 Subject: [PATCH] Some refactors to fast http2 workers --- src/client.rs | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/client.rs b/src/client.rs index 29fda01e..535c8c7a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1945,6 +1945,8 @@ pub mod fast { let client = client.clone(); let token = token.clone(); local.spawn_local(Box::pin(async move { + let mut has_err = false; + let mut result_data_err = ResultData::default(); loop { let client = client.clone(); match setup_http2(&client).await { @@ -2016,20 +2018,22 @@ pub mod fast { } if connection_gone { - return; + break; } } Err(err) => { if counter.fetch_add(1, Ordering::Relaxed) < n_tasks { - let mut result_data = ResultData::default(); - result_data.push(Err(err)); - report_tx.send(result_data).unwrap(); + has_err = true; + result_data_err.push(Err(err)); } else { - return; + break; } } } } + if has_err { + report_tx.send(result_data_err).unwrap(); + } })); } @@ -2143,6 +2147,8 @@ pub mod fast { let token = token.clone(); let is_end = is_end.clone(); local.spawn_local(Box::pin(async move { + let mut has_err = false; + let mut result_data_err = ResultData::default(); loop { let client = client.clone(); match setup_http2(&client).await { @@ -2209,19 +2215,21 @@ pub mod fast { } if connection_gone { - return; + break; } } Err(err) => { - let mut result_data = ResultData::default(); - result_data.push(Err(err)); - report_tx.send(result_data).unwrap(); + has_err = true; + result_data_err.push(Err(err)); if is_end.load(Ordering::Relaxed) { - return; + break; } } } } + if has_err { + report_tx.send(result_data_err).unwrap(); + } })); }