2 releases

0.1.1 Jan 5, 2024
0.1.0 Jan 4, 2024

#901 in Game dev

Download history 357/week @ 2024-06-30 592/week @ 2024-07-07 171/week @ 2024-07-14 132/week @ 2024-07-21 173/week @ 2024-07-28 229/week @ 2024-08-04 168/week @ 2024-08-11 317/week @ 2024-08-18 199/week @ 2024-08-25 288/week @ 2024-09-01 202/week @ 2024-09-08 238/week @ 2024-09-15 619/week @ 2024-09-22 517/week @ 2024-09-29 263/week @ 2024-10-06 359/week @ 2024-10-13

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

Apache-2.0

47KB
588 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
~36K SLoC