Skip to main content

poll_until

Function poll_until 

Source
pub async fn poll_until(done: &mut dyn FnMut() -> bool) -> bool
Expand description

Poll done until it returns true or READY_TIMEOUT elapses, starting at 2ms and doubling to a 50ms ceiling. Returns whether it flipped in time.

The backoff is the point. The daemon boots in about 20ms, so a fixed 50ms tick spent more time waiting than the daemon spent starting - it was most of the measured 97ms cold lev run. Doubling to the same 50ms ceiling leaves the slow path (a daemon that genuinely takes seconds) unchanged while making the common path cost one 2ms sleep.

done is checked before the first sleep, so a predicate that is already true costs nothing.

&mut dyn FnMut rather than impl FnMut: a generic parameter gives rustc one monomorphization per call site and llvm-cov instruments each separately - it reported 18 of 26 instantiations as 0-hit here even though the union of them covers every line. A trait object is one instantiation however many callers there are. Same reason run/task.rs’s resolve_task_with takes one, and the cost is a vtable dispatch on a loop that sleeps between iterations.