use std::thread; use tokio::runtime; use tokio::time; use std::time::{Duration, Instant}; use tokio::runtime::Runtime; pub fn time_interval<F>(rt:&mut Runtime,millsecond:u64,f:F) where F:Fn(), F: Sync + 'static, F: Send + 'static, { let millsecond =300; rt.spawn(async move { let mut interval = tokio::time::interval(Duration::from_millis(millsecond)); interval.tick().await; let start = Instant::now(); println!("time:{:?}", start); loop { interval.tick().await; f(); println!("time:{:?}", start.elapsed()); } }); }