#定时器 #休眠 #取消

可取消定时器

一个可以被中断的定时器

1个不稳定版本

0.1.0 2019年4月9日

#1620异步

Download history 28/week @ 2024-03-11 27/week @ 2024-03-18 30/week @ 2024-03-25 51/week @ 2024-04-01 16/week @ 2024-04-08 18/week @ 2024-04-15 23/week @ 2024-04-22 16/week @ 2024-04-29 16/week @ 2024-05-06 21/week @ 2024-05-13 20/week @ 2024-05-20 13/week @ 2024-05-27 25/week @ 2024-06-03 14/week @ 2024-06-10 16/week @ 2024-06-17 40/week @ 2024-06-24

97 每月下载量
3 crate 中使用

MIT/Apache

8KB
88

cancellable-timer

Crate实现了一个带有可取消的sleep方法的定时器。

示例

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);
}

许可证: MIT/Apache-2.0


lib.rs:

Crate实现了一个带有可取消的sleep方法的定时器。

示例

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);
}

依赖项

~0.6–1MB
~14K SLoC