pub struct TimeoutGuard<C = SystemTimeoutClock> { /* private fields */ }Expand description
Deterministic timeout guard wrapper with enforcement.
The TimeoutGuard extends TimeoutClassifier with active timeout enforcement
via cancellation signaling when a timeout occurs.
Implementations§
Source§impl<C> TimeoutGuard<C>where
C: TimeoutClock,
impl<C> TimeoutGuard<C>where
C: TimeoutClock,
Sourcepub fn with_clock(clock: C) -> Self
pub fn with_clock(clock: C) -> Self
Creates a timeout guard with an explicit clock implementation.
Sourcepub fn with_poll_interval(self, interval: Duration) -> Self
pub fn with_poll_interval(self, interval: Duration) -> Self
Sets the watchdog poll interval. Default is 1ms.
Sourcepub fn execute<T, F>(
&self,
timeout_secs: Option<u64>,
operation: F,
) -> GuardedExecution<T>where
F: FnOnce() -> T,
pub fn execute<T, F>(
&self,
timeout_secs: Option<u64>,
operation: F,
) -> GuardedExecution<T>where
F: FnOnce() -> T,
Executes operation, captures elapsed time, and classifies timeout outcome.
The timeout decision is deterministic for a given (timeout_secs, elapsed).
This method is provided for backward compatibility; use TimeoutClassifier::execute_and_classify
when only classification is needed without any enforcement semantics.
Sourcepub fn execute_with_cancellation<T, F>(
&self,
timeout_secs: Option<u64>,
operation: F,
) -> CancellableExecution<T>where
F: FnOnce(&CancellationContext) -> T,
pub fn execute_with_cancellation<T, F>(
&self,
timeout_secs: Option<u64>,
operation: F,
) -> CancellableExecution<T>where
F: FnOnce(&CancellationContext) -> T,
Executes operation with cancellation support, capturing elapsed time and classifying timeout.
When a timeout is configured, this method starts an attempt-local watchdog worker. The watchdog sleeps until the timeout deadline and requests cancellation if the operation has not completed yet. The watchdog is deterministically joined before returning from this method.
Timeout classification remains inspectable output, but enforcement does not depend on post-return classification. Enforcement (cancellation request) can happen during active handler execution.
Cleanup invariant: watchdog lifecycle is panic-safe and always joined via scoped lifecycle teardown before return or unwind propagation.
Sourcepub fn execute_with_external_cancellation<T, F>(
&self,
timeout_secs: Option<u64>,
cancellation_context: CancellationContext,
operation: F,
) -> CancellableExecution<T>where
F: FnOnce(&CancellationContext) -> T,
pub fn execute_with_external_cancellation<T, F>(
&self,
timeout_secs: Option<u64>,
cancellation_context: CancellationContext,
operation: F,
) -> CancellableExecution<T>where
F: FnOnce(&CancellationContext) -> T,
Executes operation with an externally-provided cancellation context.
Identical to execute_with_cancellation
except the caller supplies the CancellationContext. This allows the
dispatch loop to retain a clone of the context so it can signal
cancellation (e.g. budget exhaustion) while the handler is running.
Trait Implementations§
Source§impl<C: Clone> Clone for TimeoutGuard<C>
impl<C: Clone> Clone for TimeoutGuard<C>
Source§fn clone(&self) -> TimeoutGuard<C>
fn clone(&self) -> TimeoutGuard<C>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more