use core::time::Duration;
use std::time::Instant;
pub const REACHED: Duration = Duration::from_secs(120);
pub async fn until<F, Fut>(described: &str, mut condition: F)
where
F: FnMut() -> Fut,
Fut: core::future::Future<Output = Option<String>>,
{
let deadline = Instant::now() + REACHED;
let mut last = String::from("(nothing was read yet)");
while Instant::now() < deadline {
match condition().await {
None => return,
Some(seen) => last = seen,
}
tokio::time::sleep(Duration::from_millis(500)).await;
}
panic!("waited {REACHED:?} for {described}; the last thing read was {last}");
}