#![cfg_attr(nightly, int_error_matching)] #![allow(dead_code)] use tokio::{ select, time::{ self, Duration, }, sync::{ mpsc, }, task, }; mod interval; mod config; async fn do_thing_every() -> Result<(mpsc::Sender<()>, task::JoinHandle<()>), Box> { let mut interval = time::interval(Duration::from_secs(10)); let (tx, mut rx) = mpsc::channel(16); let handle = tokio::spawn(async move { println!("starting?"); loop { let mut tick = interval.tick(); tokio::pin!(tick); loop { select!{ _ = &mut tick => { // Do the things println!("yes"); break; } command = rx.recv() => { // We got interrupt, interpret `command` here. // `continue` to continue waiting on this interval, break to go to next, return to stop println!("no"); continue; } } } } }); Ok((tx, handle)) } #[tokio::main] async fn main() -> Result<(), Box> { let (mut tx, h) = do_thing_every().await?; loop { time::delay_for(Duration::from_secs(6)).await; tx.send(()).await?; } h.await; Ok(()) }