Experimental library for sleeping periodically in Rust code.
Cargo.toml:
toml
[dependencies]
snooze-rs = "0.0.3"
Crate root:
rust
extern crate snooze;
extern crate time;
Basic usage:
```rust use snooze::{Snooze, SnoozeError}; use time::duration::Duration;
fn sleepandwork() -> Result<(), SnoozeError> { let mut snooze = try!(Snooze::new(Duration::milliseconds(42))); while shouldcontinue() { try!(snooze.wait()); dothings(); } Ok(()) } ```
The function do_things()
will be called approximately every 42 ms, depending on
system timer accuracy and assuming do_things() takes less than 42 ms.