Intermittent Sleeping
Sleeps for a while and returns the control flow afterwards. Can be used to check for user input (eg: CTRL+C) while sleeping or updating a status bar.
let total = from_secs; // Sleeping for a total of 1 s
let len = from_millis; // Interrupting the sleep after 100 ms
let snoozy = new; // `total` start at class initialization
// while snoozy.accurate_snooze(len): // <- higher accuracy with the `accuracy` feature
while snoozy.snooze
Accuracy
cargo add isleep --features=accuracy
The accuracy of sleep duration is depending on the operating system.
Sleeping for less than 15 ms won't work reliably (eg: on Windows).
For more accurate sleeping the accuracy feature and the accurate_snooze function can be used.
This relies on the spin-sleep crate for improved accuracy.