use std::time::Instant;
use query_planning::error::Result;
use crate::runtime::ExecutionCancellation;
#[derive(Debug, Clone)]
pub struct AttemptCancellation {
execution: ExecutionCancellation,
deadline: Option<Instant>,
}
impl AttemptCancellation {
pub(crate) fn new(deadline: Option<Instant>) -> Self {
Self { execution: ExecutionCancellation::with_deadline(deadline), deadline }
}
pub fn cancel(&self) {
self.execution.cancel()
}
pub fn is_cancelled(&self) -> bool {
self.execution.is_cancelled()
}
pub fn deadline(&self) -> Option<Instant> {
self.deadline
}
pub fn is_expired(&self) -> bool {
self.execution.is_expired()
}
pub fn execution_cancellation(&self) -> ExecutionCancellation {
self.execution.clone()
}
pub fn check(&self, operation: &'static str) -> Result<()> {
self.execution.check(operation)
}
}