This commit is contained in:
Luna Yao
2026-04-17 17:45:43 +02:00
parent 6b01554c17
commit a60f101bda
13 changed files with 137 additions and 168 deletions
+12 -7
View File
@@ -79,7 +79,7 @@ impl<R: Send + 'static> AsyncRuntime<R> {
Ok(())
}
pub async fn stop(&self, timeout: Duration) -> Option<Result<R, JoinError>> {
pub async fn stop(&self, timeout: Option<Duration>) -> Option<Result<R, JoinError>> {
let state = {
let mut state = self.state.lock();
match &*state {
@@ -104,12 +104,17 @@ impl<R: Send + 'static> AsyncRuntime<R> {
};
token.cancel();
let result = if let Ok(result) = tokio::time::timeout(timeout, &mut task).await {
result
} else {
task.abort();
tracing::warn!("task stop timeout after {:?}, aborted", timeout);
task.await
let result = match timeout {
Some(duration) => {
if let Ok(result) = tokio::time::timeout(duration, &mut task).await {
result
} else {
task.abort();
tracing::warn!("task stop timeout after {:?}, aborted", duration);
task.await
}
}
None => task.await,
};
{