macro_rules! deadline {
($wait_limit: expr, $condition: expr) => { ... };
}Expand description
Requires a condition closure to return true before the specified duration has elapsed.
This will panic if the provided closure doesn’t evaluate to true before the provided duration
expires. Internally, it creates a Future from the closure that is polled until it returns
true or times out. This ensures the call is non-blocking to the async runtime.
§Examples
Waiting for an AtomicI32 to be incremented to 42:
let x = Arc::new(AtomicI32::new(41));
let y = 42;
let x_clone = x.clone();
tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_millis(5)).await;
x_clone.fetch_add(1, Ordering::SeqCst);
});
deadline!(Duration::from_millis(10), move || {
x.load(Ordering::Relaxed) == y
});