Skip to content

Commit

Permalink
Merge pull request #227 from UiPath/fix-wait-hang
Browse files Browse the repository at this point in the history
Fix hang in wait_all_exit
  • Loading branch information
Tim-Zhang authored Sep 25, 2024
2 parents 4aac6ff + 092d768 commit d43d84f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/asynchronous/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,25 @@ impl Notifier {
/// Wait for all [`Waiter`]s to drop.
pub async fn wait_all_exit(&self) -> Result<(), Elapsed> {
//debug_assert!(self.shared.is_shutdown());
if self.waiters() == 0 {
return Ok(());
}
let wait = self.wait();
if self.waiters() == 0 {
return Ok(());
}
wait.await
}

async fn wait(&self) -> Result<(), Elapsed> {
if let Some(tm) = self.wait_time {
timeout(tm, self.shared.notify_exit.notified()).await
timeout(tm, self.wait()).await
} else {
self.shared.notify_exit.notified().await;
self.wait().await;
Ok(())
}
}

async fn wait(&self) {
while self.waiters() > 0 {
let notified = self.shared.notify_exit.notified();
if self.waiters() == 0 {
return;
}
notified.await;
// Some waiters could have been created in the meantime
// by calling `subscribe`, loop again
}
}
}

impl Drop for Notifier {
Expand Down

0 comments on commit d43d84f

Please sign in to comment.