Expand description
Utils using spin_sleep.
§Example: Frame limiter
Interval may be used to limit a loop to a max fps by calling Interval::tick
at the start or end of each loop.
// Create an interval to tick 144 times each second
let mut interval = spin_sleep_util::interval(Duration::from_secs(1) / 144);
loop {
compute_something(); // do loop work
// tick: sleep using a SpinSleeper until next tick.
// The default `Skip` missed ticke behaviour is appropriate for a frame limiter
interval.tick();
}Structs§
- Interval
- Interval returned by
intervalandinterval_at. - Rate
Reporter - Helper for regularly reporting a rate per second, like fps.
Enums§
- Missed
Tick Behavior - Defines the behavior of an
Intervalwhen it misses a tick.
Functions§
- interval
- Creates new
Intervalthat spin-sleeps with interval ofperiod. The first tick returns immediately. The defaultMissedTickBehaviorisSkip. - interval_
at - Creates new
Intervalthat spin-sleeps with interval ofperiodwith the first tick returning atstart. The defaultMissedTickBehaviorisSkip.