Skip to main content

causa_runtime/
control.rs

1//! Cancellation and deadline wait helper for runtime operations.
2
3use causa_kernel::{CallControl, ControlError};
4
5/// Races the control plane's cancellation token and optional deadline.
6pub(crate) async fn wait_for_stop(control: &CallControl) -> ControlError {
7    tokio::select! {
8        biased;
9        _ = control.cancellation_token().cancelled() => ControlError::Cancelled,
10        _ = async {
11            match control.deadline() {
12                Some(deadline) => tokio::time::sleep_until(deadline.into()).await,
13                None => std::future::pending::<()>().await,
14            }
15        } => ControlError::TimedOut,
16    }
17}