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(
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user