diff options
Diffstat (limited to 'src/bin')
-rw-r--r-- | src/bin/server.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/bin/server.rs b/src/bin/server.rs index e8fa735..881cc4d 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use std::io::Write; use std::net::TcpListener; use std::thread::sleep; -use std::time::Duration; +use std::time::{Duration, Instant}; use space::constants; use space::mass::Mass; @@ -42,6 +42,8 @@ fn main() { connections.push(new_connection); } _ => { + let timer = Instant::now(); + for connection in &mut connections { if connection.open { let mut ship = masses.remove(&connection.name).unwrap(); @@ -62,7 +64,11 @@ fn main() { masses.insert(key.to_string(), mass); } - sleep(Duration::from_millis(constants::SLEEP_DURATION)); + if timer.elapsed().as_millis() < constants::LOOP_DURATION_MS.into() { + sleep(Duration::from_millis( + constants::LOOP_DURATION_MS - timer.elapsed().as_millis() as u64, + )); + } } } } |