Use newly &self Supervisor.wait to drop wait loop

This commit is contained in:
Félix Saparelli 2022-01-31 00:04:56 +13:00
parent 995d38078e
commit 9a736c5eb9
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
1 changed files with 5 additions and 13 deletions

View File

@ -1,6 +1,6 @@
use std::{sync::Arc, time::Duration};
use std::sync::Arc;
use tokio::{sync::RwLock, time::timeout};
use tokio::sync::RwLock;
use crate::{command::Supervisor, error::RuntimeError, signal::process::SubSignal};
@ -43,17 +43,9 @@ impl ProcessHolder {
}
pub async fn wait(&self) -> Result<(), RuntimeError> {
// Loop to allow concurrent operations while waiting
loop {
if let Some(p) = self.0.write().await.as_mut() {
match timeout(Duration::from_millis(20), p.wait()).await {
Err(_timeout) => continue,
Ok(Err(err)) => break Err(err),
Ok(Ok(())) => break Ok(()),
}
} else {
break Ok(());
}
if let Some(p) = self.0.read().await.as_ref() {
p.wait().await?;
}
Ok(())
}
}