Poll a predicate up to `deadline`, sleeping `step` between attempts. Panics with a descriptive message if the predicate never holds.
(
desc: &str,
deadline: Duration,
step: Duration,
mut pred: F,
)
| 390 | /// attempts. Panics with a descriptive message if the predicate |
| 391 | /// never holds. |
| 392 | pub async fn wait_for<F: FnMut() -> bool>( |
| 393 | desc: &str, |
| 394 | deadline: Duration, |
| 395 | step: Duration, |
| 396 | mut pred: F, |
| 397 | ) { |
| 398 | // no-determinism: test timing observability |
| 399 | let start = std::time::Instant::now(); |
| 400 | while start.elapsed() < deadline { |
| 401 | if pred() { |
| 402 | return; |
| 403 | } |
| 404 | tokio::time::sleep(step).await; |
| 405 | } |
| 406 | panic!("timed out after {:?} waiting for: {}", deadline, desc); |
| 407 | } |
no test coverage detected