From 39beadc1d952ca919ad632152fdf338b584bef5a Mon Sep 17 00:00:00 2001 From: hr567 Date: Thu, 7 Mar 2024 15:15:06 +0800 Subject: [PATCH] Make the semaphore work correctly Signed-off-by: hr567 --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9f2121b..51b54df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,7 +104,7 @@ async fn main() -> io::Result<()> { let task = tokio::spawn( async move { tracing::debug!("Prepare to acquire a permit to start"); - let _ = permits.acquire().await.unwrap(); + let _permit = permits.acquire().await.unwrap(); tracing::info!("Start to read file"); let buf = fs::read(&task.file).await?; @@ -147,9 +147,11 @@ async fn main() -> io::Result<()> { }) .progress_chars("#>-"); process.set_style(style); - while analyzed_size.load(Ordering::Acquire) < total_size - && !finished_flag.load(Ordering::Acquire) - { + while analyzed_size.load(Ordering::Acquire) < total_size { + if finished_flag.load(Ordering::Acquire) { + tracing::warn!("Some tasks failed to complete"); + break; + } process.set_position(analyzed_size.load(Ordering::Acquire) as u64); sleep(Duration::from_millis(100)).await; }