feat: add cancellation

This commit is contained in:
2026-01-12 12:07:04 +01:00
parent c0f06beb4d
commit 514b6ab333
3 changed files with 11 additions and 4 deletions

2
Cargo.lock generated
View File

@@ -544,7 +544,7 @@ dependencies = [
[[package]] [[package]]
name = "nocontrol" name = "nocontrol"
version = "0.0.2" version = "0.0.3"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"async-trait", "async-trait",

View File

@@ -3,7 +3,7 @@ members = ["crates/*", "examples/*"]
resolver = "2" resolver = "2"
[workspace.package] [workspace.package]
version = "0.0.2" version = "0.0.3"
[workspace.dependencies] [workspace.dependencies]
nocontrol = { path = "crates/nocontrol" } nocontrol = { path = "crates/nocontrol" }

View File

@@ -38,11 +38,18 @@ impl<TOperator: Operator> ControlPlane<TOperator> {
self self
} }
pub async fn execute(&self) -> anyhow::Result<()> { pub async fn execute(&self) -> anyhow::Result<()> {
self.execute_with_cancellation(CancellationToken::new())
.await
}
pub async fn execute_with_cancellation(
&self,
cancellation: CancellationToken,
) -> anyhow::Result<()> {
tracing::info!(worker_id = %self.worker_id, "starting control plane"); tracing::info!(worker_id = %self.worker_id, "starting control plane");
let cancellation_token = CancellationToken::new(); let cancellation_token = cancellation;
let child_token = cancellation_token.child_token(); let child_token = cancellation_token.child_token();
if let Some(deadline) = self.deadline { if let Some(deadline) = self.deadline {
tokio::spawn(async move { tokio::spawn(async move {