use causa_kernel::{CallControl, ControlError};
pub(crate) async fn wait_for_stop(control: &CallControl) -> ControlError {
tokio::select! {
biased;
_ = control.cancellation_token().cancelled() => ControlError::Cancelled,
_ = async {
match control.deadline() {
Some(deadline) => tokio::time::sleep_until(deadline.into()).await,
None => std::future::pending::<()>().await,
}
} => ControlError::TimedOut,
}
}