arch: split ConfigRepository, extract polling, consolidate conversions, decouple protocol
- Value↔JSON: From impls on domain Value behind `json` feature, delete 4 duplicate converters - ConfigRepository split into ConfigRepository (12), UserRepository (3), WidgetStateCache (2) - polling orchestration moved from bootstrap to application::polling_service - WidgetRenderer in client-domain owns scroll/cache, both clients use it - network loop consolidated into client-application::run_connection_loop - protocol crate drops domain dep, Wire↔Domain conversions move to adapters
This commit is contained in:
42
crates/client-application/src/connection_loop.rs
Normal file
42
crates/client-application/src/connection_loop.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use client_domain::NetworkPort;
|
||||
use protocol::{ServerMessage, decode_server_message};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
pub fn run_connection_loop<N: NetworkPort>(
|
||||
net: &mut N,
|
||||
server_addr: &str,
|
||||
poll_interval: Duration,
|
||||
reconnect_delay: Duration,
|
||||
mut on_message: impl FnMut(ServerMessage),
|
||||
mut on_connection_change: impl FnMut(bool),
|
||||
) {
|
||||
loop {
|
||||
if !net.is_connected() {
|
||||
match net.connect(server_addr) {
|
||||
Ok(()) => on_connection_change(true),
|
||||
Err(_) => {
|
||||
on_connection_change(false);
|
||||
thread::sleep(reconnect_delay);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match net.receive() {
|
||||
Ok(Some(payload)) => {
|
||||
if let Ok(msg) = decode_server_message(&payload) {
|
||||
on_message(msg);
|
||||
}
|
||||
}
|
||||
Ok(None) => {
|
||||
thread::sleep(poll_interval);
|
||||
}
|
||||
Err(_) => {
|
||||
let _ = net.disconnect();
|
||||
on_connection_change(false);
|
||||
thread::sleep(reconnect_delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user