2 releases

0.1.1 Jan 5, 2024
0.1.0 Jan 4, 2024

#1267 in Game dev

Download history 232/week @ 2024-11-17 276/week @ 2024-11-24 328/week @ 2024-12-01 387/week @ 2024-12-08 338/week @ 2024-12-15 114/week @ 2024-12-22 147/week @ 2024-12-29 314/week @ 2025-01-05 268/week @ 2025-01-12 610/week @ 2025-01-19 436/week @ 2025-01-26 505/week @ 2025-02-02 541/week @ 2025-02-09 596/week @ 2025-02-16 504/week @ 2025-02-23 643/week @ 2025-03-02

2,318 downloads per month
Used in 8 crates (2 directly)

Apache-2.0

48KB
597 lines

spin_sleep_util crates.io Documentation

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();
}

lib.rs:

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();
}

Dependencies

~0–6.5MB
~31K SLoC