see-you-later

Crates.iosee-you-later
lib.rssee-you-later
version0.1.0
sourcesrc
created_at2020-05-09 22:07:51.679151
updated_at2020-05-09 22:07:51.679151
descriptionDelay and schedule async task
homepage
repositoryhttps://github.com/wolf4ood/see-you-later
max_upload_size
id239415
size42,304
Enrico Risa (wolf4ood)

documentation

README

see-you-later

Delay and schedule async task

Tests status Coverage status Download docs.rs docs

Install

Install from crates.io

[dependencies]
see-you-later = "0.1"

Example

with smol oneshot schedule

use see_you_later::once;
use std::sync::{
    atomic::{AtomicBool, Ordering},
    Arc,
};
use std::time::Duration;

#[smol_potat::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let invoked = Arc::new(AtomicBool::new(false));
    let invoked1 = invoked.clone();
    let (_, task) = once(Duration::from_secs(1), || async {
        invoked1.store(true, Ordering::Relaxed);
    });

    task.await;

    assert_eq!(true, invoked.load(Ordering::Relaxed));
    Ok(())
}

with smol periodic schedule.

use see_you_later::every;
use smol::{self, Task};
use std::time::Duration;
use wait_for_me::CountDownLatch;
#[smol_potat::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let latch = CountDownLatch::new(10);
    let inner_latch = latch.clone();
    let (cancel, task) = every(Duration::from_millis(100), || async {
        inner_latch.count_down().await;
    });
    Task::spawn(async move {
        latch.wait().await;
        cancel.cancel().await
    })
    .detach();
    task.await;
    Ok(())
}
Commit count: 27

cargo fmt