use eyre::Result; use async_trait::async_trait; use tokio::task::spawn_local; use std::time::Instant; use std::sync::Arc; use tokio::sync::oneshot; use crate::endpoint::Endpoint; pub struct RircdState { endpoints: Vec>, //to determine program runtime creation_timestamp: Option, plainlog: Option<()>, sqlite_log: Option<()>, postgres_log: Option<()>, } impl RircdState { pub fn new() -> Result { //TODO impl Ok(RircdState { endpoints: vec![], creation_timestamp: Some(Instant::now()), plainlog: None, sqlite_log: None, postgres_log: None, }) } //TODO impl pub fn from_config(config: String) -> Result { Self::new() } pub async fn run(mut self) -> Result<()> { //try to start each endpoint self.endpoints.iter().filter(|ep| ep.is_active()).for_each(|endpoint| { let endpoint_name = endpoint.name(); let (success_status_send,success_status_recv) = oneshot::channel::>(); tokio::spawn(endpoint.clone().listen(success_status_send)); //TODO color err msg //TODO paralelize and sync at the end spawn_local(async move { println!("starting {} | {}", endpoint_name, match success_status_recv.await { Ok(_) => format!("SUCCEEDED |"), Err(e) => format!("FAILED| <{}>", e), }); }); }); Ok(()) } }