use std::time::Duration;
use async_repeater::RepeaterEntry;
#[derive(Debug, Clone)]
pub struct Entry {
id: u8,
interval: Duration,
}
impl Entry {
pub fn new(id: u8, interval: Duration) -> Self {
Self { id, interval }
}
}
impl RepeaterEntry for Entry {
type Key = u8;
fn interval(&self) -> Duration {
self.interval
}
fn key(&self) -> Self::Key {
self.id
}
}
#[tokio::main(flavor = "current_thread")]
async fn main() {
let callback = |entry, _| async move { println!("Popped {entry:?}") };
let handle = async_repeater::Repeater::with_capacity(25).run_with_async_callback(callback);
let dur = Duration::from_secs(5);
let repetition = vec![Entry::new(0, dur), Entry::new(1, dur), Entry::new(2, dur)];
for repetition in repetition {
handle.insert(repetition).await.unwrap();
tokio::time::sleep(Duration::from_secs(1)).await;
}
tokio::signal::ctrl_c().await.unwrap();
handle.stop().await.unwrap();
println!("Stopping cycler");
}