Module time

Module time 

Source
Expand description

Timeout support for cancellation.

This module provides timeout wrappers that add deadline-based cancellation to any Stop implementation.

§Overview

  • WithTimeout - Wraps any Stop and adds a deadline
  • TimeoutExt - Extension trait providing .with_timeout() and .with_deadline()

§Example

use almost_enough::{StopSource, Stop, TimeoutExt};
use std::time::Duration;

let source = StopSource::new();
let stop = source.as_ref().with_timeout(Duration::from_secs(30));

// Stop will trigger if cancelled OR if 30 seconds pass
assert!(!stop.should_stop());

§Timeout Tightening

Timeouts can only get stricter, never looser. This is safe for composition:

use almost_enough::{StopSource, TimeoutExt};
use std::time::Duration;

let source = StopSource::new();
let stop = source.as_ref()
    .with_timeout(Duration::from_secs(60))  // 60 second outer limit
    .with_timeout(Duration::from_secs(10)); // 10 second inner limit

// Effective timeout is ~10 seconds (the tighter of the two)

Structs§

WithTimeout
A Stop wrapper that adds a deadline.

Traits§

TimeoutExt
Extension trait for adding timeouts to any Stop implementation.