RircdState::run()

This commit is contained in:
some body 2021-09-16 14:33:48 -05:00
parent e399e302c4
commit 21f4282cca
3 changed files with 29 additions and 1 deletions

View File

@ -1,8 +1,12 @@
use eyre::Result;
use async_trait::async_trait;
use tokio::sync::oneshot;
use std::sync::Arc;
#[async_trait]
pub trait Endpoint {
fn name(&self) -> String;
fn is_active(&self) -> bool;
async fn listen(self: Arc<Self>, success_status_send: oneshot::Sender<Result<()>>);
}

View File

@ -12,5 +12,7 @@ use state::RircdState;
async fn main() -> Result<()> {
let s = RircdState::new()?;
s.run().await?;
Ok(())
}

View File

@ -1,6 +1,8 @@
use eyre::Result;
use async_trait::async_trait;
use std::time::Instant;
use std::sync::Arc;
use tokio::sync::oneshot;
use crate::endpoint::Endpoint;
@ -25,4 +27,24 @@ impl RircdState {
postgres_log: None,
})
}
//TODO impl
pub fn from_config(config: String) -> Result<Self> {
Self::new()
}
pub async fn run(mut self) -> Result<()> {
for endpoint in self.endpoints {
let endpoint_name = endpoint.name();
let (success_status_send,success_status_recv) = oneshot::channel::<Result<()>>();
tokio::spawn(endpoint.listen(success_status_send));
//TODO color err msg
println!("starting {} | {}", endpoint_name,
match success_status_recv.await {
Ok(_) => format!("SUCCEEDED |"),
Err(e) => format!("FAILED| <{}>", e),
});
}
Ok(())
}
}