Skip to main content

eventually_blocking

Function eventually_blocking 

Source
pub fn eventually_blocking<F>(
    timeout: Duration,
    probe: F,
) -> Result<(), TestError>
where F: FnMut() -> bool,
Expand description

The runtime-free eventually: retries probe until it returns true or timeout elapses, sleeping between attempts with std::thread::sleep.

Because it never touches an async runtime, it needs no runtime feature and can be called from an ordinary #[test].

use std::time::Duration;
use test_better_async::eventually_blocking;
use test_better_core::TestResult;

let mut polls = 0;
// The probe passes on its third call, so polling stops there.
eventually_blocking(Duration::from_secs(1), || {
    polls += 1;
    polls >= 3
})?;