Block until the watermark reaches `target`, the timeout elapses, or the watcher is closed.
(&self, target: u64, timeout: Duration)
| 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)] |