use std::sync::mpsc; use std::thread; use client_application::run_connection_loop; use super::RenderEvent; use crate::config::{NET_THREAD_STACK_SIZE, NET_POLL_INTERVAL, NET_RECONNECT_DELAY}; use crate::adapters::network::Esp32Network; pub fn spawn(server_addr: String, tx: mpsc::Sender) { thread::Builder::new() .stack_size(NET_THREAD_STACK_SIZE) .name("net".into()) .spawn(move || { let mut net = Esp32Network::new(); let tx_msg = tx.clone(); let tx_status = tx.clone(); run_connection_loop( &mut net, &server_addr, NET_POLL_INTERVAL, NET_RECONNECT_DELAY, move |msg| { let _ = tx_msg.send(RenderEvent::Server(msg)); }, move |connected| { let _ = tx_status.send(RenderEvent::ConnectionStatus(connected)); }, ); }) .expect("failed to spawn network thread"); }