Repository navigation
v0.4.3
What's New
almost-enough: DebouncedTimeout
A deadline wrapper that learns how fast check() is called and skips most Instant::now() reads. Useful when the caller adds a deadline but the library controls check frequency — neither side can optimize the other's hot path.
How it works: Starts by reading the clock every call, then adapts skip_mod so clock reads happen roughly every 100μs (configurable). Adapts immediately when calls slow down (safety), gradually when they speed up (stability).
Performance:
| Workload | WithTimeout | DebouncedTimeout |
|---|---|---|
| Tight loop (no work) | 59M checks/s | 648M checks/s (11x) |
| Jittery (~100ns avg) | 29M checks/s | 62M checks/s (2.1x) |
| Codec (4KB chunks) | 17.1 GiB/s | 18.1 GiB/s (equivalent) |
API:
use almost_enough::{Stopper, DebouncedTimeoutExt};
use std::time::Duration;
let stop = Stopper::new()
.with_debounced_timeout(Duration::from_secs(30));
// Pass to any library accepting impl StopAlso available: with_debounced_deadline(), with_target_interval(), tighten(), tighten_deadline().
Maximum deadline overshoot equals the target interval (default 100μs).