MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / wait_for

Method wait_for

nodedb-cluster/src/applied_watcher/watcher.rs:87–110  ·  view source on GitHub ↗

Block until the watermark reaches `target`, the timeout elapses, or the watcher is closed.

(&self, target: u64, timeout: Duration)

Source from the content-addressed store, hash-verified

85 /// Block until the watermark reaches `target`, the timeout elapses,
86 /// or the watcher is closed.
87 pub fn wait_for(&self, target: u64, timeout: Duration) -> WaitOutcome {
88 let deadline = Instant::now() + timeout;
89 let mut guard = self.state.lock().unwrap_or_else(|p| p.into_inner());
90 loop {
91 if guard.applied >= target {
92 return WaitOutcome::Reached;
93 }
94 if guard.closed {
95 return WaitOutcome::GroupGone;
96 }
97 let remaining = match deadline.checked_duration_since(Instant::now()) {
98 Some(r) if !r.is_zero() => r,
99 _ => return WaitOutcome::TimedOut,
100 };
101 let wait = self
102 .cv
103 .wait_timeout(guard, remaining)
104 .unwrap_or_else(|p| p.into_inner());
105 guard = wait.0;
106 if wait.1.timed_out() && guard.applied < target && !guard.closed {
107 return WaitOutcome::TimedOut;
108 }
109 }
110 }
111}
112
113#[cfg(test)]

Callers 7

bump_notifies_waiterFunction · 0.45
propose_surrogate_hwmFunction · 0.45
propose_and_waitFunction · 0.45
propose_drainFunction · 0.45
await_cluster_readyFunction · 0.45

Calls 3

nowFunction · 0.85
lockMethod · 0.80
is_zeroMethod · 0.80

Tested by 2

bump_notifies_waiterFunction · 0.36