#![cfg_attr(nightly, feature(int_error_matching))] #![cfg_attr(nightly, feature(const_fn))] #![cfg_attr(nightly, feature(maybe_uninit_ref))] #![allow(dead_code)] use tokio::{ select, time::{ self, Duration, }, sync::{ mpsc, }, task, }; use lazy_static::lazy_static; mod util; use util::*; mod log; mod sys; mod interval; mod config; mod hot; mod context; mod job; mod stat; //This is a test function, when we have a real job server, remove it. 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 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> { log::init(log::Level::Debug); let child = sys::fork::detach_closure(None, None, |parent| { println!("Parent: {:?}, us: {}", parent, sys::get_pid()); //let pipe = parent.pipe(); //use tokio::prelude::*; //pipe.write_all(b"Hello there").await.expect("io error c"); //tokio::time::delay_for(tokio::time::Duration::from_secs(3)).await; //std::thread::sleep_ms(3000); println!("Exiting child"); }).await?; println!("Child: {:?}", child); println!("Waitpid nb {:?}", child.await.map_err(|x| x.to_string())); // end test log::Logger::global().add_hook(log::custom::LogFileHook::new(log::Level::Debug, "test.log", "test.err.log", false)); debug!("Logger initialised"); //TODO: Parse config first stat::print_stats(); //debug!("{:?}",sys::user::get_users()); #[cfg(feature="watcher")] { let oneesan = hot::watch("."); { let mut recv = oneesan.hook("src/main.rs", hot::filter::ALL).await; while let Some(event) = recv.recv().await { important!("Got ev {:?}", event); break; } } oneesan.shutdown().await.expect("oneesan panic"); } println!("{:?}", config::parse_global_single("example.rori").await.expect("Waaaaaah")); //let (mut tx, h) = do_thing_every().await?; // loop { // time::delay_for(Duration::from_secs(6)).await; // tx.send(()).await?; // } // h.await?; Ok(()) }