qubit_lock/monitor/async_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 condition-wait capability.
11
12use crate::monitor::AsyncMonitorFuture;
13
14/// Waits asynchronously for predicates over protected monitor state.
15pub trait AsyncConditionWaiter {
16 /// State protected by the monitor.
17 type State;
18
19 /// Returns a future that waits until the predicate becomes true.
20 ///
21 /// The predicate and action run while the monitor state is locked.
22 fn async_wait_until<'a, R, P, F>(
23 &'a self,
24 predicate: P,
25 action: F,
26 ) -> AsyncMonitorFuture<'a, R>
27 where
28 R: Send + 'a,
29 P: FnMut(&Self::State) -> bool + Send + 'a,
30 F: FnOnce(&mut Self::State) -> R + Send + 'a;
31
32 /// Returns a future that waits while the predicate remains true.
33 ///
34 /// The predicate and action run while the monitor state is locked.
35 fn async_wait_while<'a, R, P, F>(
36 &'a self,
37 predicate: P,
38 action: F,
39 ) -> AsyncMonitorFuture<'a, R>
40 where
41 R: Send + 'a,
42 P: FnMut(&Self::State) -> bool + Send + 'a,
43 F: FnOnce(&mut Self::State) -> R + Send + 'a;
44}