Skip to main content

oxide_batch/
fault.rs

1//! The cancellable backoff waiting contract.
2
3use std::time::Duration;
4
5use crate::{BoxFuture, StopToken};
6
7/// The result of one cancellable backoff wait.
8#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
9#[non_exhaustive]
10pub enum BackoffOutcome {
11    /// The complete delay elapsed.
12    Elapsed,
13    /// Cooperative stop cancelled the wait.
14    Stopped,
15}
16
17/// An injected monotonic, cancellable delay source.
18///
19/// Implementations must not detach a task or timer, must observe the supplied
20/// [`StopToken`] while waiting, and must not consult wall-clock time.
21pub trait BackoffSleeper: Send + Sync {
22    /// Waits for `delay` unless cooperative stop is observed first.
23    fn sleep<'a>(&'a self, delay: Duration, stop: &'a StopToken) -> BoxFuture<'a, BackoffOutcome>;
24}