qubit_lock/monitor/wait_timeout_result.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026.
4 * Haixing Hu, Qubit Co. Ltd.
5 *
6 * All rights reserved.
7 *
8 ******************************************************************************/
9//! # Wait Timeout Result
10//!
11//! Provides the result returned by predicate-based timed monitor waits.
12//!
13//! # Author
14//!
15//! Haixing Hu
16
17/// Result of waiting for a predicate with an overall timeout.
18///
19/// This type is returned by
20/// [`Monitor::wait_timeout_while`](super::Monitor::wait_timeout_while) and
21/// [`Monitor::wait_timeout_until`](super::Monitor::wait_timeout_until). It is
22/// more explicit than `Option<R>`: a ready predicate produces [`Self::Ready`],
23/// while an expired timeout produces [`Self::TimedOut`].
24///
25/// # Type Parameters
26///
27/// * `R` - The value produced after the protected state satisfies the
28/// predicate.
29///
30/// # Example
31///
32/// ```rust
33/// use std::time::Duration;
34///
35/// use qubit_lock::lock::{Monitor, WaitTimeoutResult};
36///
37/// let monitor = Monitor::new(true);
38/// let result = monitor.wait_timeout_until(
39/// Duration::from_secs(1),
40/// |ready| *ready,
41/// |ready| {
42/// *ready = false;
43/// "ready"
44/// },
45/// );
46///
47/// assert_eq!(result, WaitTimeoutResult::Ready("ready"));
48/// ```
49#[derive(Debug, Clone, Copy, PartialEq, Eq)]
50pub enum WaitTimeoutResult<R> {
51 /// The predicate became ready before the timeout and produced this value.
52 Ready(R),
53 /// The timeout elapsed before the predicate became ready.
54 TimedOut,
55}