Expand description
Operation-level timeouts and deadline management.
This module provides utilities for adding timeouts to async operations, deadline propagation through contexts, and cancellation handling.
§Example
ⓘ
use ringkernel_core::timeout::{TimeoutLayer, Deadline, with_timeout};
use std::time::Duration;
// Simple timeout wrapper
let result = with_timeout(Duration::from_secs(5), async {
// Long-running operation
kernel.send(message).await
}).await?;
// Deadline propagation
let deadline = Deadline::from_duration(Duration::from_secs(30));
let ctx = OperationContext::new().with_deadline(deadline);
// Check remaining time
if let Some(remaining) = ctx.remaining_time() {
if remaining < Duration::from_millis(100) {
return Err("Not enough time remaining");
}
}Structs§
- Cancellation
Token - A token that can be used to cancel an operation.
- Deadline
- A deadline for an operation.
- Operation
Context - Context for tracking operation state including deadlines and cancellation.
- Timeout
- Future that wraps another future with a timeout.
- Timeout
Error - Error returned when an operation times out.
- Timeout
Stats - Statistics for timeout tracking.
- Timeout
Stats Snapshot - Snapshot of timeout statistics.
Functions§
- timeout
- Wrap a future with a timeout.
- timeout_
named - Wrap a future with a timeout and operation name.
- with_
timeout - Execute an async operation with timeout using tokio.
- with_
timeout_ named - Execute an async operation with timeout and operation name.