cancellable-timer 0.1.0

A timer that can be interrupted.
Documentation
  • Coverage
  • 77.78%
    7 out of 9 items documented1 out of 9 items with examples
  • Size
  • Source code size: 24.41 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 586.83 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • Emm54321/cancellable-timer
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Emm54321

cancellable-timer

Crate that implements a timer with a sleep method that can be cancelled.

Example

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