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);
let mut timeout = tokio::time::interval(Duration::from_secs(5));
timeout.tick().await;
loop {
tokio::select! {
_ = timeout.tick() => {
if let Ok(state) = self.running_state.try_lock()
&& *state == RunningState::Stopping
if let Ok(rstate) = self.running_state.try_lock()
&& *rstate == RunningState::Stopping
{
break;
}
dbg!("tick");
},
r = self.socket.recv_from(&mut buf) => {
match r {

View file

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

View file

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

View file

@ -69,8 +69,8 @@ impl App {
loop {
terminal.draw(|frame| self.draw(frame))?;
self.handle_events().await?;
if let Ok(lock) = self.state.running_state.try_lock()
&& *lock == RunningState::Stopping
if let Ok(rstate) = self.state.running_state.try_lock()
&& *rstate == RunningState::Stopping
{
break;
}
@ -111,7 +111,7 @@ impl App {
impl Widget for &App {
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![
" Send ".into(),
"<S>".blue().bold(),