1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*******************************************************************************
*
* Copyright (c) 2025 - 2026 Haixing Hu.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0.
*
******************************************************************************/
//! Blocking condition-wait capability.
/// Waits for predicates over protected monitor state.
pub trait ConditionWaiter {
/// State protected by the monitor.
type State;
/// Blocks until the predicate becomes true, then runs an action.
///
/// The predicate and action run while the monitor state is locked.
///
/// # Arguments
///
/// * `predicate` - Predicate that returns `true` when the state is ready.
/// * `action` - Action to run after the predicate becomes true.
///
/// # Returns
///
/// The value returned by `action`.
fn wait_until<R, P, F>(&self, predicate: P, action: F) -> R
where
P: FnMut(&Self::State) -> bool,
F: FnOnce(&mut Self::State) -> R;
/// Blocks while the predicate remains true, then runs an action.
///
/// The predicate and action run while the monitor state is locked.
///
/// # Arguments
///
/// * `predicate` - Predicate that returns `true` while waiting should
/// continue.
/// * `action` - Action to run after the predicate becomes false.
///
/// # Returns
///
/// The value returned by `action`.
fn wait_while<R, P, F>(&self, predicate: P, action: F) -> R
where
P: FnMut(&Self::State) -> bool,
F: FnOnce(&mut Self::State) -> R;
}