Expand description
test-better-async: async and timing helpers.
Home of the runtime-agnostic timeout abstraction that backs
check!(fut).completes_within(..).
§The runtime gate
Timing out a future needs a runtime-provided sleep. The runtime is chosen
at compile time by the mutually-exclusive tokio, async-std, and smol
cargo features (in that priority order if more than one is on, which only
happens under --all-features). One private function, selected_sleep,
is the single place that cfg-branches on them.
If no runtime feature is enabled, the crate still compiles: the
RuntimeAvailable marker trait simply has no implementation. Because
run_within is bounded where F: RuntimeAvailable on its generic
future type, that bound is deferred to the call site (a bound on a concrete
type would be rejected at the definition instead). The user who calls
completes_within without a runtime feature is the one who sees the
error, and the #[diagnostic::on_unimplemented] message on
RuntimeAvailable points them at the feature flags.
§Polling: eventually
eventually retries a bool-returning probe until it passes or a
deadline is reached, sleeping with exponential Backoff in between. The
async form needs the same runtime gate as the timeout (its inter-probe
sleep is runtime-provided), so its probe closure carries the deferred
RuntimeAvailable bound. eventually_blocking is the runtime-free
sibling: it sleeps with std::thread::sleep, so a non-async codebase can
use it with no runtime feature at all.
Structs§
- Backoff
- The inter-probe sleep schedule for
eventuallyandeventually_blocking. - Elapsed
- The error returned by
run_withinwhen the future outlives its limit.
Traits§
- Runtime
Available - A marker trait, implemented for every type when (and only when) a runtime feature is enabled.
Functions§
- eventually
- Retries
probeuntil it resolves totrue, or fails oncetimeoutelapses. - eventually_
blocking - The runtime-free
eventually: retriesprobeuntil it returnstrueortimeoutelapses, sleeping between attempts withstd::thread::sleep. - eventually_
blocking_ with eventually_blockingwith an explicitBackoffschedule instead of the default.- eventually_
with eventuallywith an explicitBackoffschedule instead of the default.- run_
within - Awaits
fut, but gives up afterlimit.