use std::future::Future; use std::pin::Pin; use std::time::Duration; use tokio::task::JoinHandle; use tokio::time; use crate::{lang, rs_println}; pub type Schedule = (Duration, fn() -> Pin + Send>>); pub async fn run_schedule Pin + Send>>>(d: Duration, f: F) { let mut ticker = time::interval(d); loop { ticker.tick().await; f().await; } } pub async fn run_schedules(schedules: Vec) { let mut handles: Vec> = vec![]; rs_println!("{}", lang!("starting_schedules")); for (d, f) in schedules { let handle = tokio::spawn(run_schedule(d, f)); handles.push(handle); } for handle in handles { let _ = handle.await; } }