Skip to main content

Module timeout

Module timeout 

Source
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§

CancellationToken
A token that can be used to cancel an operation.
Deadline
A deadline for an operation.
OperationContext
Context for tracking operation state including deadlines and cancellation.
Timeout
Future that wraps another future with a timeout.
TimeoutError
Error returned when an operation times out.
TimeoutStats
Statistics for timeout tracking.
TimeoutStatsSnapshot
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.