2 releases

0.1.1 Jan 5, 2024
0.1.0 Jan 4, 2024

#25 in #sleep

Download history 206/week @ 2024-08-26 243/week @ 2024-09-02 205/week @ 2024-09-09 248/week @ 2024-09-16 625/week @ 2024-09-23 509/week @ 2024-09-30 253/week @ 2024-10-07 364/week @ 2024-10-14 262/week @ 2024-10-21 325/week @ 2024-10-28 293/week @ 2024-11-04 281/week @ 2024-11-11 231/week @ 2024-11-18 277/week @ 2024-11-25 324/week @ 2024-12-02 388/week @ 2024-12-09

1,242 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–6MB
~32K SLoC