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

Function wait_for

nodedb-cluster/tests/common/test_node.rs:392–407  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

390/// attempts. Panics with a descriptive message if the predicate
391/// never holds.
392pub 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}

Calls 3

nowFunction · 0.85
elapsedMethod · 0.80
predFunction · 0.50

Tested by

no test coverage detected