tokio-postponable-delay

Crates.iotokio-postponable-delay
lib.rstokio-postponable-delay
version0.1.0
sourcesrc
created_at2020-05-23 12:57:55.254037
updated_at2020-05-23 12:57:55.254037
descriptionA tokio Delay that can be pushed back without instantiating new delays
homepage
repositoryhttps://github.com/p-avital/tokio-postponable-delay
max_upload_size
id244871
size6,730
Pierre Avital (p-avital)

documentation

README

A tokio Delay that you can push back

How does it work?

Like a normal tokio::time::Delay, except it will check whether its target time of resolution has moved before resolving, and reschedule itself if needed.

For now, this works by dropping the previous Delay and instantiating a new one to reschedule itself.

How do I use it?

async fn typical_usage() {
    let target = std::time::Instant::now() + std::time::Duration::from_millis(10);
    let delay = ResettableDelay::new(target);
    let handle = delay.get_handle();
    std::thread::spawn(move || {
        std::thread::sleep(std::time::Duration::from_millis(5));
        let target = std::time::Instant::now() + std::time::Duration::from_millis(10);
        handle.postpone(target)
    });
    delay.await;
}
Commit count: 1

cargo fmt