more shutdown tweaking

This commit is contained in:
Joe Ardent 2025-07-07 15:16:18 -07:00
parent c02e4bc879
commit 9fa9df476d
4 changed files with 13 additions and 11 deletions

View file

@ -29,16 +29,16 @@ impl JoecalState {
println!("Listening on multicast addr: {}", config.multicast_addr); println!("Listening on multicast addr: {}", config.multicast_addr);
let mut timeout = tokio::time::interval(Duration::from_secs(5)); let mut timeout = tokio::time::interval(Duration::from_secs(5));
timeout.tick().await;
loop { loop {
tokio::select! { tokio::select! {
_ = timeout.tick() => { _ = timeout.tick() => {
if let Ok(state) = self.running_state.try_lock() if let Ok(rstate) = self.running_state.try_lock()
&& *state == RunningState::Stopping && *rstate == RunningState::Stopping
{ {
break; break;
} }
dbg!("tick");
}, },
r = self.socket.recv_from(&mut buf) => { r = self.socket.recv_from(&mut buf) => {
match r { match r {

View file

@ -59,6 +59,5 @@ impl JoecalState {
} }
async fn shutdown(mut rx: mpsc::Receiver<()>) { async fn shutdown(mut rx: mpsc::Receiver<()>) {
println!("shutting down");
rx.recv().await.unwrap_or_default() rx.recv().await.unwrap_or_default()
} }

View file

@ -8,6 +8,7 @@ use std::{
collections::HashMap, collections::HashMap,
net::{Ipv4Addr, SocketAddr, SocketAddrV4}, net::{Ipv4Addr, SocketAddr, SocketAddrV4},
sync::Arc, sync::Arc,
time::Duration,
}; };
use models::Device; use models::Device;
@ -84,8 +85,8 @@ impl JoecalState {
let announcement_handle = { let announcement_handle = {
tokio::spawn(async move { tokio::spawn(async move {
loop { loop {
if let Ok(lock) = state.running_state.try_lock() if let Ok(rstate) = state.running_state.try_lock()
&& *lock == RunningState::Stopping && *rstate == RunningState::Stopping
{ {
break; break;
} }
@ -103,8 +104,8 @@ impl JoecalState {
pub async fn stop(&self) { pub async fn stop(&self) {
loop { loop {
if let Ok(mut lock) = self.running_state.try_lock() { if let Ok(mut rstate) = self.running_state.try_lock() {
*lock = RunningState::Stopping; *rstate = RunningState::Stopping;
if self if self
.stop_tx .stop_tx
.get() .get()
@ -115,6 +116,8 @@ impl JoecalState {
{ {
break; break;
} }
} else {
tokio::time::sleep(Duration::from_millis(777)).await;
} }
} }
} }

View file

@ -69,8 +69,8 @@ impl App {
loop { loop {
terminal.draw(|frame| self.draw(frame))?; terminal.draw(|frame| self.draw(frame))?;
self.handle_events().await?; self.handle_events().await?;
if let Ok(lock) = self.state.running_state.try_lock() if let Ok(rstate) = self.state.running_state.try_lock()
&& *lock == RunningState::Stopping && *rstate == RunningState::Stopping
{ {
break; break;
} }
@ -111,7 +111,7 @@ impl App {
impl Widget for &App { impl Widget for &App {
fn render(self, area: Rect, buf: &mut Buffer) { fn render(self, area: Rect, buf: &mut Buffer) {
let title = Line::from(" Counter App Tutorial ".bold()); let title = Line::from(" Joecalsend ".bold());
let instructions = Line::from(vec![ let instructions = Line::from(vec![
" Send ".into(), " Send ".into(),
"<S>".blue().bold(), "<S>".blue().bold(),