cmkl/spring-2025/sen-109/00010/rust-chat-server/tui/src/main.rs

33 lines
965 B
Rust

use state_store::StateStore;
use termination::create_termination;
use ui_management::UiManager;
mod state_store;
mod termination;
mod ui_management;
use termination::{Interrupted, Terminator};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let (terminator, mut interrupt_rx) = create_termination();
let (state_store, state_rx) = StateStore::new();
let (ui_manager, action_rx) = UiManager::new();
tokio::try_join!(
state_store.main_loop(terminator, action_rx, interrupt_rx.resubscribe()),
ui_manager.main_loop(state_rx, interrupt_rx.resubscribe()),
)?;
if let Ok(reason) = interrupt_rx.recv().await {
match reason {
Interrupted::UserInt => println!("exited per user request"),
Interrupted::OsSigInt => println!("exited because of an os sig int"),
}
} else {
println!("exited because of an unexpected error");
}
Ok(())
}