Skip to content

Commit

Permalink
send all data to newly connected devices
Browse files Browse the repository at this point in the history
  • Loading branch information
zzeneg committed Jan 1, 2025
1 parent 4d74b55 commit 9b20f49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,18 @@ fn start(data_sender: broadcast::Sender<Vec<u8>>, mut is_connected_receiver: mps
connected_count += if is_connected { 1 } else { -1 };
tracing::info!("Connected devices: {}", connected_count);

if connected_count > 0 && !is_started {
tracing::info!("Starting providers");
is_started = true;
providers.iter().for_each(|p| p.start());
} else if connected_count == 0 && is_started {
// if new device is connected - restart providers to send all available data
if is_started && (connected_count == 0 || is_connected) {
tracing::info!("Stopping providers");
is_started = false;
providers.iter().for_each(|p| p.stop());
std::thread::sleep(std::time::Duration::from_millis(200));
}

if !is_started && connected_count > 0 {
tracing::info!("Starting providers");
is_started = true;
providers.iter().for_each(|p| p.start());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/providers/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Provider for TimeProvider {
send_data(&synced_time, &data_sender);
}

std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(std::time::Duration::from_millis(100));
}

tracing::info!("Time Provider stopped");
Expand Down

0 comments on commit 9b20f49

Please sign in to comment.