You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.1 KiB

#![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<dyn std::error::Error>>
{
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<dyn std::error::Error>> {
let (mut tx, h) = do_thing_every().await?;
loop {
time::delay_for(Duration::from_secs(6)).await;
tx.send(()).await?;
}
h.await;
Ok(())
}