Make the semaphore work correctly

Signed-off-by: hr567 <hr567@hr567.me>
This commit is contained in:
hr567 2024-03-07 15:15:06 +08:00
parent eff24bb8e5
commit 39beadc1d9
Signed by: hr567
SSH Key Fingerprint: SHA256:AUrHz/3TKmc6tf4wqaaEPV/BGQ4aULSp7g76FpqujYw

View File

@ -104,7 +104,7 @@ async fn main() -> io::Result<()> {
let task = tokio::spawn( let task = tokio::spawn(
async move { async move {
tracing::debug!("Prepare to acquire a permit to start"); 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"); tracing::info!("Start to read file");
let buf = fs::read(&task.file).await?; let buf = fs::read(&task.file).await?;
@ -147,9 +147,11 @@ async fn main() -> io::Result<()> {
}) })
.progress_chars("#>-"); .progress_chars("#>-");
process.set_style(style); process.set_style(style);
while analyzed_size.load(Ordering::Acquire) < total_size while analyzed_size.load(Ordering::Acquire) < total_size {
&& !finished_flag.load(Ordering::Acquire) if finished_flag.load(Ordering::Acquire) {
{ tracing::warn!("Some tasks failed to complete");
break;
}
process.set_position(analyzed_size.load(Ordering::Acquire) as u64); process.set_position(analyzed_size.load(Ordering::Acquire) as u64);
sleep(Duration::from_millis(100)).await; sleep(Duration::from_millis(100)).await;
} }