qubit_lock/monitor/async_timeout_condition_waiter.rs
1/*******************************************************************************
2 *
3 * Copyright (c) 2025 - 2026 Haixing Hu.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0.
8 *
9 ******************************************************************************/
10//! Asynchronous timeout condition-wait capability.
11
12use std::time::Duration;
13
14use crate::monitor::{
15 AsyncConditionWaiter,
16 AsyncMonitorFuture,
17 WaitTimeoutResult,
18};
19
20/// Waits asynchronously for predicates over protected state with timeouts.
21pub trait AsyncTimeoutConditionWaiter: AsyncConditionWaiter {
22 /// Returns a future that waits until the predicate becomes true or times out.
23 ///
24 /// The timeout budget is measured from this method call.
25 fn async_wait_until_for<'a, R, P, F>(
26 &'a self,
27 timeout: Duration,
28 predicate: P,
29 action: F,
30 ) -> AsyncMonitorFuture<'a, WaitTimeoutResult<R>>
31 where
32 R: Send + 'a,
33 P: FnMut(&Self::State) -> bool + Send + 'a,
34 F: FnOnce(&mut Self::State) -> R + Send + 'a;
35
36 /// Returns a future that waits while the predicate remains true or times out.
37 ///
38 /// The timeout budget is measured from this method call.
39 fn async_wait_while_for<'a, R, P, F>(
40 &'a self,
41 timeout: Duration,
42 predicate: P,
43 action: F,
44 ) -> AsyncMonitorFuture<'a, WaitTimeoutResult<R>>
45 where
46 R: Send + 'a,
47 P: FnMut(&Self::State) -> bool + Send + 'a,
48 F: FnOnce(&mut Self::State) -> R + Send + 'a;
49}