see-you-later
Delay and schedule async task
Install
Install from crates.io
[dependencies]
see-you-later = "0.1"
Example
with smol oneshot schedule
```rust
use seeyoulater::once;
use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
};
use std::time::Duration;
[smol_potat::main]
async fn main() -> Result<(), Box> {
let invoked = Arc::new(AtomicBool::new(false));
let invoked1 = invoked.clone();
let (, task) = once(Duration::fromsecs(1), || async {
invoked1.store(true, Ordering::Relaxed);
});
task.await;
assert_eq!(true, invoked.load(Ordering::Relaxed));
Ok(())
}
```
with smol periodic schedule.
```rust
use seeyoulater::every;
use smol::{self, Task};
use std::time::Duration;
use waitforme::CountDownLatch;
[smol_potat::main]
async fn main() -> Result<(), Box> {
let latch = CountDownLatch::new(10);
let innerlatch = latch.clone();
let (cancel, task) = every(Duration::frommillis(100), || async {
innerlatch.countdown().await;
});
Task::spawn(async move {
latch.wait().await;
cancel.cancel().await
})
.detach();
task.await;
Ok(())
}
```