macro_rules! wait_for {
($condition:expr, $timeout:expr, $poll_interval:expr, $msg:expr) => { ... };
}Expand description
A macro that waits for a condition to be met, polling at a regular interval.
This macro is useful for testing asynchronous operations where you need to wait for a state change.
It will repeatedly execute the provided $condition closure until it returns Some(value) or the $timeout is reached.
§Arguments
$condition: A closure that returnsOption<T>. When it returnsSome(T), the macro returns that value.$timeout: Astd::time::Durationspecifying the maximum time to wait.$poll_interval: Astd::time::Durationspecifying how often to poll the condition.$msg: A message to include in the panic if the macro times out.
§Panics
Panics if the $timeout is reached before the $condition returns Some(T).
The panic message includes the total elapsed time, the number of checks performed, the poll interval, and the provided $msg.
§Example
use rust_test_framework::wait_for;
use std::time::Duration;
let result = wait_for!(
|| Some(42),
Duration::from_secs(1),
Duration::from_millis(10),
"should not time out"
);
assert_eq!(result, 42);