server: lifecycle

This commit is contained in:
Luna Yao
2026-03-31 03:37:23 +02:00
parent 70fba64e17
commit 08a1640e30
3 changed files with 11 additions and 7 deletions
+3 -3
View File
@@ -195,7 +195,7 @@ impl<T: Send + 'static> AsyncRuntime<T> {
self.inner.lock().as_ref().map(|r| r.token.clone())
}
pub fn start<F, Fut>(&self, factory: F)
pub fn start<F, Fut>(&self, token: Option<CancellationToken>, factory: F)
where
F: FnOnce(CancellationToken) -> Fut,
Fut: Future<Output = T> + Send + 'static,
@@ -207,8 +207,8 @@ impl<T: Send + 'static> AsyncRuntime<T> {
return;
}
}
let token = CancellationToken::new();
let token = token.unwrap_or_default();
runtime.replace(AsyncRuntimeInner {
task: tokio::spawn(factory(token.clone())).into(),
token,