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.

51 lines
799 B

#![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<dyn std::error::Error>>
{
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<dyn std::error::Error>> {
Ok(())
}