pub async fn poll_until<F, Fut>(
timeout: Duration,
interval: Duration,
condition: F,
) -> Result<(), String>Expand description
Poll a condition until it becomes true or timeout is reached.
This is useful for testing asynchronous operations that may take some time to complete, such as cache expiration, rate limit window resets, or background task completion.
§Arguments
timeout- Maximum duration to wait for the condition to become trueinterval- Duration to wait between each poll attemptcondition- Async closure that returnstruewhen the desired state is reached
§Returns
Ok(())if the condition becomes true within the timeoutErr(String)if the timeout is reached before the condition becomes true
§Examples
ⓘ
use reinhardt_testkit::poll_until;
use std::time::Duration;
// Poll until a cache entry expires
poll_until(
Duration::from_millis(200),
Duration::from_millis(10),
|| async {
// Check if cache entry has expired
// cache.get("key").await.is_none()
true
}
).await.expect("Condition should be met");