use std::{
thread,
time::{Duration, Instant},
};
pub fn poll_until<T>(mut f: impl FnMut() -> Option<T>, timeout: Duration) -> Option<T> {
let deadline = Instant::now() + timeout;
loop {
if let Some(value) = f() {
return Some(value);
}
if Instant::now() >= deadline {
return None;
}
thread::sleep(Duration::from_millis(10));
}
}