Make the semaphore work correctly
Signed-off-by: hr567 <hr567@hr567.me>
This commit is contained in:
parent
eff24bb8e5
commit
39beadc1d9
10
src/main.rs
10
src/main.rs
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user