#[macro_use] extern crate serde; #[macro_use] extern crate log; #[macro_use] extern crate futures; mod config; mod imap; use anyhow::Result; use clap::Clap; use futures::future::FutureExt; use tokio::sync::oneshot; use crate::config::Config; type ExitListener = oneshot::Receiver<()>; /// The panorama daemon runs in the background and communicates with other panorama components over Unix sockets. #[derive(Debug, Clap)] struct Options { // /// Config file path (defaults to XDG) // #[clap(long = "config", short = 'c')] // config_file: Option, /// Verbose mode (-v, -vv, -vvv, etc) #[clap(short = 'v', long = "verbose", parse(from_occurrences))] verbose: usize, } #[tokio::main] async fn main() -> Result<()> { let opt = Options::parse(); println!("{:?}", opt); stderrlog::new() .module(module_path!()) .verbosity(opt.verbose) .init() .unwrap(); let (_, mut config_watcher) = config::spawn_config_watcher_system()?; loop { let (exit_tx, exit_rx) = oneshot::channel(); let new_config = config_watcher.borrow().clone(); tokio::spawn(run_with_config(new_config, exit_rx)); // wait till the config has changed, then tell the current thread to stop config_watcher.changed().await?; let _ = exit_tx.send(()); } } async fn run_with_config(config: Config, exit: ExitListener) -> Result<()> { println!("run with config: {:?}", config); let mut exit = exit.fuse(); loop { select! { _ = exit => break, } } Ok(()) }