Crates.io | cancellable-timer |
lib.rs | cancellable-timer |
version | 0.1.0 |
source | src |
created_at | 2019-04-09 09:40:42.695104 |
updated_at | 2019-04-09 09:40:42.695104 |
description | A timer that can be interrupted. |
homepage | https://github.com/Emm54321/cancellable-timer |
repository | https://github.com/Emm54321/cancellable-timer.git |
max_upload_size | |
id | 126797 |
size | 20,471 |
Crate that implements a timer with a sleep
method that can be cancelled.
use std::time::Duration;
use cancellable_timer::*;
fn main() {
let (mut timer, canceller) = Timer::new2().unwrap();
// Spawn a thread that will cancel the timer after 2s.
std::thread::spawn(move || {
std::thread::sleep(Duration::from_secs(2));
println!("Stop the timer.");
canceller.cancel();
});
println!("Wait 10s");
let r = timer.sleep(Duration::from_secs(10));
println!("Done: {:?}", r);
}
License: MIT/Apache-2.0