use crate::service::Service; use crate::shutdown::Shutdown; use log::info; pub struct Server { control: Shutdown, } impl Server { pub fn new(control: Shutdown) -> Self { info!("BOOT: START"); // Bootstrap the components. info!("BOOT: READY"); Self { control } } pub async fn run(&mut self) { info!("SERVER: RUN"); let child_control = self.control.replicate(); let service_loop = tokio::spawn(async { let mut network_service = Service::new(child_control); network_service.serve().await; }); self.control.recv().await; info!("SERVER: RECEIVED CONTROL SIGNAL"); service_loop.abort(); info!("SERVICE: CANCELLED"); info!("SERVER: STOP"); } }