#![cfg_attr(nightly, int_error_matching)] #![allow(dead_code)] use tokio::{ select, time::{ self, Duration, }, sync::{ oneshot, }, task, }; mod interval; mod config; async fn do_thing_every() -> Result<(oneshot::Sender<()>, task::JoinHandle<()>), Box> { let mut interval = time::interval(Duration::from_secs(1)); let (tx, mut rx) = oneshot::channel(); let handle = tokio::spawn(async move { println!("starting?"); loop { select!{ _ = interval.tick() => { // Do the things println!("yes"); } _ = &mut rx => { // We got cancel println!("no"); break; } } } }); Ok((tx, handle)) } #[tokio::main] async fn main() -> Result<(), Box> { Ok(()) }